Skip to content

Commit

Permalink
rewrite: from Pascal to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
plc-user committed Oct 3, 2022
1 parent ad6c6c1 commit 1ed25ae
Show file tree
Hide file tree
Showing 16 changed files with 15,816 additions and 46 deletions.
35 changes: 35 additions & 0 deletions QET_ElementScaler.cbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="QET_ElementScaler" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Release">
<Option output="QET_ElementScaler" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-std=c++17" />
</Compiler>
<Unit filename="inc/pugixml/pugiconfig.hpp" />
<Unit filename="inc/pugixml/pugixml.cpp" />
<Unit filename="inc/pugixml/pugixml.hpp" />
<Unit filename="main.cpp" />
<Unit filename="main.h" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# QET_ElementScaler

QET_ElementScaler is a commandline-tool to scale QElectroTech-Elements with constant factor(s) and save the changed data to a renamed file.
With the optional parameter &quot;-o&quot; or &quot;--stdout&quot; the scaled element is written to stdout and no new file is created.
The optional parameter &quot;-i&quot; or &quot;--stdin&quot; is used to read the input-data from stdin and the output is forced to stdout.<br>
With the optional parameter &quot;-o&quot; or &quot;--stdout&quot; the changed data is written to stdout and no new file is created.

It compiles with Lazarus 2.2.2 and FreePascal 3.2.2 on Debian/GNU Linux (unstable) and ReactOS (0.4.15-dev-4888).

It compiles with GCC with C++17 activated on Debian/GNU Linux (unstable) and ReactOS (0.4.15-dev-5075).
The ReactOS-Build can also be used with Win in a cmd-window.<br>

QET_ElementScaler can process one file at a time.
Expand All @@ -13,15 +13,44 @@ If you want to edit all files in a directory, you need to call QET_ElementScaler
You do not want to (or can't) compile the FreePascal program yourself? Download the executable file suitable for your operating system from the releases-page and use that.<br><br>
Hint: <br>
Get familiar with the command line before using this software.
General support for using the command line for the various systems cannot be provided here.<br>
General support for using the command line for the various systems cannot be provided here.



usage:<br>
QET_ElementScaler [-i] [-o] &lt;file&gt; &lt;scaling-factor&gt; <br>
(as used in Batch-File &quot;scale.cmd&quot; and shell-script &quot;scale.sh&quot;)<br>
QET_ElementScaler [options] &lt;file&gt; &lt;scaling-factor&gt; <br>
(as used in Batch-File &quot;scale.cmd&quot; and shell-script &quot;scale.sh&quot;) <br>

or:<br>
QET_ElementScaler [-i] [-o] [-x FactorForX] [-y FactorForY] -f FILENAME<br>
QET_ElementScaler [options] [-x FactorForX] [-y FactorForY] -f FILENAME <br>

<br>

<br>
available options: <br>
-i | --stdin input-data is read from stdin, a given filename is <br>
ignored and scaled element will be written to stdout <br>
-o | --stdout output will be written to stdout <br>
-x VALUE or <br>
--factorx VALUE factor for x-values (x, rx, width, ...) <br>
-y VALUE or <br>
--factory VALUE factor for y-values (y, ry, height, ...) <br>
-f FILENAME or <br>
--file FILENAME the file that will be used <br>
-h | --help show this help <br>
<br>

<br>
there are also some &quot;long-opt&quot;-only options: <br>
&quot;--RemoveAllTerminals&quot; removes all terminals from the element <br>
(useful for front-views or &quot;thumbnails&quot;) <br>
&quot;--FlipPolyHorizontal&quot; flips ALL Lines and polygons horizontally <br>
(useful during creation of elements) <br>
&quot;--FlipPolyVertical&quot; flips ALL Lines and polygons vertically <br>
(useful during creation of elements) <br>
&quot;--OverwriteOriginal&quot; the original file is replaced by scaled one <br>
(CAUTION: Be careful with this option!) <br>
<br>

<br>
examples to use data from stdin: <br>
Expand All @@ -30,6 +59,12 @@ QET_ElementScaler -i 2.0 &lt; ElementToScale.elmt &gt; ScaledElement.elmt <
or use a pipe like this <br>
cat ElementToScale.elmt | QET_ElementScaler -i 2.0 | OtherSoftwareBinary <br>
<br>
extended mode and long-options are also possible:<br>
QET_ElementScaler --stdin -x 2 -y 3 &lt; ElementToScale.elmt &gt; ScaledElement.elmt <br>
extended mode is also possible:<br>
QET_ElementScaler -i -x 2 -y 3 &lt; ElementToScale.elmt &gt; ScaledElement.elmt <br>
<br>
<br>

QET_ElementScaler uses Arseny Kapoulkine's &quot;pugixml&quot; (https://pugixml.org)
to handle the content of the Element-File. <br>
Thank you, Arseny! <br>
<br>
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions _old_pascal-version/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# QET_ElementScaler

QET_ElementScaler is a commandline-tool to scale QElectroTech-Elements with constant factor(s) and save the changed data to a renamed file.
With the optional parameter &quot;-o&quot; or &quot;--stdout&quot; the scaled element is written to stdout and no new file is created.
The optional parameter &quot;-i&quot; or &quot;--stdin&quot; is used to read the input-data from stdin and the output is forced to stdout.<br>

It compiles with Lazarus 2.2.2 and FreePascal 3.2.2 on Debian/GNU Linux (unstable) and ReactOS (0.4.15-dev-4888).
The ReactOS-Build can also be used with Win in a cmd-window.<br>

QET_ElementScaler can process one file at a time.
If you want to edit all files in a directory, you need to call QET_ElementScaler from a batch-, cmd- or shell-script-file such as the ones available here.<br>

You do not want to (or can't) compile the FreePascal program yourself? Download the executable file suitable for your operating system from the releases-page and use that.<br><br>
Hint: <br>
Get familiar with the command line before using this software.
General support for using the command line for the various systems cannot be provided here.<br>


usage:<br>
QET_ElementScaler [-i] [-o] &lt;file&gt; &lt;scaling-factor&gt; <br>
(as used in Batch-File &quot;scale.cmd&quot; and shell-script &quot;scale.sh&quot;)<br>

or:<br>
QET_ElementScaler [-i] [-o] [-x FactorForX] [-y FactorForY] -f FILENAME<br>

<br>
examples to use data from stdin: <br>
QET_ElementScaler -i 2.0 &lt; ElementToScale.elmt &gt; ScaledElement.elmt <br>
<br>
or use a pipe like this <br>
cat ElementToScale.elmt | QET_ElementScaler -i 2.0 | OtherSoftwareBinary <br>
<br>
extended mode and long-options are also possible:<br>
QET_ElementScaler --stdin -x 2 -y 3 &lt; ElementToScale.elmt &gt; ScaledElement.elmt <br>
<br>
37 changes: 37 additions & 0 deletions _old_pascal-version/scale.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@echo skaliere QET - Element-Dateien ...

@echo off & setlocal

rem Wo liegt das Programm?
rem Where does the Program lie?
set "ProgPfad=C:\Tools\QET_ElementScaler"

rem Wo liegen die zu skalierenden Element-Dateien?
rem Path to the directory of element-files to be scaled:
set "DataPfad=Z:\win\Elemente"

rem Welcher Faktor soll angewendet werden?
set "Skalierung=0.9"


rem ------ Ab hier nichts mehr ändern! ------
rem ------ No changes below this line! ------


rem Findet rekursiv alle passenden Dateien:
@for /r "%DataPfad%" %%i in ("*.elmt") do (
rem gefundene Dateien bearbeiten:
"%ProgPfad%\QET_ElementScaler.exe" "%%i" %Skalierung%
)


rem Rekursiv den XML-Header entfernen:
@for /r "%DataPfad%" %%i in ("*.SCALED.elmt") do (
rem gefundene Dateien bearbeiten:
more +1 < "%%i" > "%%i.txt"
rem und wieder umbenennen:
move /Y "%%i.txt" "%%i"
)


@echo + + + Fertig! + + +
35 changes: 35 additions & 0 deletions _old_pascal-version/scale.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

# scales QET - Element-files in the directory and all sub-dirs
# by the factor given here:

Skalierung="0.5"
SkalierProg="/usr/local/bin/QET_ElementScaler"

# um Leerzeichen in Dateinamen verarbeiten zu können:
# Originalzustand merken:
OFS=$IFS
# Einstellen:
IFS="
"

for i in `find . -name "*.elmt"` ; do
echo "processing $i"
# Grafik skalieren:
"$SkalierProg" "$i" "$Skalierung"
done

for i in `find . -name "*.SCALED.elmt"` ; do
echo "processing $i"
# "xml version" entfernen
grep -v -i "xml version" "$i" > /tmp/tempfile.elmt
# Dateiname wieder herstellen
cat /tmp/tempfile.elmt > "$i"
done

# aufräumen:
rm -r /tmp/tempfile.elmt

# Leerzeichen in Dateinamen - wieder Originalzustand:
IFS=$OFS
# FERTIG!
7 changes: 7 additions & 0 deletions compile.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rem compile with GCC in "path"

g++.exe -Wall -O2 -std=c++17 -c inc\pugixml\pugixml.cpp -o obj\inc\pugixml\pugixml.o
g++.exe -Wall -O2 -std=c++17 -c main.cpp -o obj\main.o
g++.exe -o QET_ElementScaler.exe obj\inc\pugixml\pugixml.o obj\main.o -s

pause
7 changes: 7 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# compile QET_ElementScaler

g++ -Wall -O2 std=c++17 -c inc/pugixml/pugixml.cpp -o obj/inc/pugixml/pugixml.o
g++ -Wall -O2 std=c++17 -c main.cpp -o obj/main.o
g++ -o QET_ElementScaler obj/inc/pugixml/pugixml.o obj/main.o -s
77 changes: 77 additions & 0 deletions inc/pugixml/pugiconfig.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* pugixml parser - version 1.12
* --------------------------------------------------------
* Copyright (C) 2006-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
* Report bugs and download new versions at https://pugixml.org/
*
* This library is distributed under the MIT License. See notice at the end
* of this file.
*
* This work is based on the pugxml parser, which is:
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
*/

#ifndef HEADER_PUGICONFIG_HPP
#define HEADER_PUGICONFIG_HPP

// Uncomment this to enable wchar_t mode
// #define PUGIXML_WCHAR_MODE

// Uncomment this to enable compact mode
// #define PUGIXML_COMPACT

// Uncomment this to disable XPath
// #define PUGIXML_NO_XPATH

// Uncomment this to disable STL
// #define PUGIXML_NO_STL

// Uncomment this to disable exceptions
// #define PUGIXML_NO_EXCEPTIONS

// Set this to control attributes for public classes/functions, i.e.:
// #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL
// #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL
// #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead

// Tune these constants to adjust memory-related behavior
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096

// Tune this constant to adjust max nesting for XPath queries
// #define PUGIXML_XPATH_DEPTH_LIMIT 1024

// Uncomment this to switch to header-only version
// #define PUGIXML_HEADER_ONLY

// Uncomment this to enable long long support
// #define PUGIXML_HAS_LONG_LONG

#endif

/**
* Copyright (c) 2006-2022 Arseny Kapoulkine
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
Loading

0 comments on commit 1ed25ae

Please sign in to comment.