Materials: Add Tools for FCMat<->ods conversion

Testing and proofreading by sgrogan

Signed-off-by: Przemo Firszt <przemo@firszt.eu>
This commit is contained in:
Przemo Firszt 2015-08-26 15:53:40 +01:00
parent 285ad9dbfa
commit 729c1b4a73
6 changed files with 231 additions and 0 deletions

View File

@ -0,0 +1,35 @@
#!/bin/bash
# Helper script that converts FCMat file into csv file
FILE=$1
FILE_BASENAME=$(basename $FILE)
if [ "$FILE_BASENAME" = "TEMPLATE.FCMat" ]
then
echo "Skipping TEMPLATE.FCMat";
exit 0
fi
if [ -f "$1.temp" ]
then
rm $1.temp
fi
if [ -f "$1.csv" ]
then
rm $1.csv
fi
echo "Processing "${FILE_BASENAME%%.FCMat}
echo "FileName = "${FILE_BASENAME%%.FCMat} > $FILE_BASENAME.temp
while read -r PROPERTY || [[ -n "$PROPERTY" ]]; do
VALUE=$(cat $FILE | awk '{if ($1!="") print $0; else "X" }' | grep -w $PROPERTY | cut -f3- -d " ")
echo $PROPERTY' = '$VALUE >> $FILE_BASENAME.temp
done < headers
echo "FileName" | tr '\n' "|" > $FILE_BASENAME.csv
cat headers | tr '\n' "|" | sed 's/|$/\n/' >> $FILE_BASENAME.csv
cat $FILE_BASENAME.temp | sed 's/^[\[,;].*//' | sed '/^$/d' | cut -d"=" -f2- | cut -d " " -f2- | sed 's/^/\"/' | sed 's/$/\"/' | tr '\n' "|" | sed 's/|$/\n/' >> $FILE_BASENAME.csv
rm $FILE_BASENAME.temp

View File

@ -0,0 +1,42 @@
WARNING: The scripts operate with limited checks and can be dangerous.
Commit your changes before using the scripts!
That directory contains set of scripts for FCMat<->ods conversion.
The main purpose of conversion FCMat<->ods is to allow batch editing as
it's much easier to edit a column in spreadsheet than 25 separate FCMat files.
Also creating new materials similar to an existing material is just
a matter of copying a row, changing file names and relevant properties.
Typical workflow:
1. Run ./make_ods.sh to create Materials.ods
2. Edit Materials.ods
4. Run ./make_FCMats.sh to create directory with new FCMat files
5. Copy edited FCMat files to StandardMaterials directory
Other scenarios:
A. Removing a property
1. Remove the property from headers file and from the TEMPLATE.FCMat file
2. Run ./make_ods.sh to create Materials.ods
3. Run ./make_FCMats.sh to create directory with new FCMat files
4. Copy FCMat files to StandardMaterials directory
B. Adding a property
1. Add the property to headers file and to the TEMPLATE.FCMat file with a description
2. Run ./make_ods.sh to create Materials.ods
3. Edit Materials.ods and fill the values of the new property (empty properties are not written to FCMat files)
3. Run ./make_FCMats.sh to create directory with new FCMat files
4. Copy FCMat files to StandardMaterials directory
C. Sorting properties as per header file order
2. Run ./make_ods.sh to create Materials.ods
3. Run ./make_FCMats.sh to create directory with new FCMat files
4. Copy FCMat files to StandardMaterials directory
Important comments:
1. First 5 lines of a FCMat file are copied without modification to the new FCMat file
2. The scripts are to be used only on linux, in the source code directory.

View File

@ -0,0 +1,51 @@
Name
NameDE
Description
DescriptionDE
DescriptionPL
Father
SpecificWeight
Vendor
ProductURL
SpecificPrice
YoungsModulus
UltimateTensileStrength
PoissonRatio
AmbientColor
Color
CompressiveStrength
Density
DiffuseColor
Elasticity
EmissiveColor
Enlargen
EnvironmentalEfficiencyClass
ExecutionInstructions
Finish
FireResistanceClass
FractureToughness
FragmentShader
KindOfMaterial
KindOfMaterialDE
MaterialNumber
Model
ModulusOfShare
Norm
SectionFillPattern
SectionLinewidth
Shininess
SoundTransmissionClass
SpecularColor
StandardCode
TexturePath
TextureScaling
ThermalConductivity
ThermalExpansionCoefficient
Transparency
UltimateStrain
UnitsPerQuantity
VertexShader
ViewColor
ViewFillPattern
ViewLinewidth
YieldStrength

View File

@ -0,0 +1,71 @@
#!/bin/bash
# That script converts Materials.ods file into FCMat files. The result files are saved in FCMAT_OUTPUT_DIR
FCMAT_OUTPUT_DIR=FCMats
MATERIALS_FILE=Materials
# Check for unoconv
which unoconv 2>&1 > /dev/null || ( echo "unoconv not found. Please install it first!" && exit 1 )
# Convert Materials.ods to Materials.csv
if [ -f "$MATERIALS_FILE.ods" ]
then
echo "Creating "$MATERIALS_FILE.csv
# 124 is field delimiter |
# 34 is text delimiter "
# 76 is encoding UTF-8
unoconv -e FilterOptions=124,34,76 -f csv $MATERIALS_FILE.ods
else
echo "Material.ods not found. Please run make_ods.sh first!"
exit 1
fi
# Helper function to retrive string from X,Y position in csv file
function get_xy() {
VALUE_XY=$(cat $MATERIALS_FILE.csv | awk -v x=$X -v y=$Y -F\| 'NR==y {print $x}' | sed 's/\"//g')
}
#Determine number of columns and rows in the Materials.csv file
NUMBER_OF_COLUMNS=$(cat $MATERIALS_FILE.csv | awk --field-separator="|" "NR==1 { print NF }")
NUMBER_OF_ROWS=$(cat $MATERIALS_FILE.csv | wc -l)
echo "Setting output directory:" $FCMAT_OUTPUT_DIR
if [ -d "$FCMAT_OUTPUT_DIR" ]
then
rm "$FCMAT_OUTPUT_DIR"/* 2>&1 > /dev/null
else
mkdir $FCMAT_OUTPUT_DIR
fi
for MAT_NO in $(seq 2 $NUMBER_OF_ROWS)
do
X=1
Y=$MAT_NO
get_xy
FCMAT_FILE=$VALUE_XY
echo "Generating material file: " $FCMAT_OUTPUT_DIR/$FCMAT_FILE.FCMat
touch $FCMAT_OUTPUT_DIR/$FCMAT_FILE.FCMat
if [ -f "../$FCMAT_FILE.FCMat" ]
then
head -n 5 ../$FCMAT_FILE.FCMat > $FCMAT_OUTPUT_DIR/$FCMAT_FILE.FCMat
else
cp new_material_header $FCMAT_OUTPUT_DIR/$FCMAT_FILE.FCMat
fi
echo "[FCMat]" >> $FCMAT_OUTPUT_DIR/$FCMAT_FILE.FCMat
for X in $(seq 2 $NUMBER_OF_COLUMNS)
do
Y=1
get_xy
PROPERTY=$VALUE_XY
Y=$MAT_NO
get_xy
VALUE=$VALUE_XY
if [ -n "$VALUE_XY" ]
then
echo $PROPERTY = $VALUE >> $FCMAT_OUTPUT_DIR/$FCMAT_FILE.FCMat;
fi
done
done

View File

@ -0,0 +1,27 @@
#!/bin/bash
# That script creates Materials.ods file from all FCMat files in current directory
FCMAT_DIR="../"
MATERIALS_FILE=Materials
# Remove exisitng $MATERIALS_FILE.csv
if [ -f "$MATERIALS_FILE.csv" ]
then
rm $MATERIALS_FILE.csv
fi
# Create new Materials.csv from all FCMat files
ls $FCMAT_DIR*.FCMat | xargs -I [] ./FCMat2csv.sh [] && ls *.csv | xargs -I [] cat [] | awk "NR==1; NR%2 == 0" > $MATERIALS_FILE.csv
# Check for unoconv
which unoconv 2>&1 > /dev/null || ( echo "unoconv not found. Please install it first!" && exit 1 )
# Convert Materials.csv to Materials.ods
echo "Creating "$MATERIALS_FILE.ods
# 124 is field delimiter |
# 34 is text delimiter "
# 76 is encoding UTF-8
unoconv -i FilterOptions=124,34,76 -f ods $MATERIALS_FILE.csv
# Remove all temporary files
rm *.csv

View File

@ -0,0 +1,5 @@
; My new amazing material file
; (c) 2015 Your Name (CC-BY 3.0)
; Information about the content of such cards you can find here:
; http://www.freecadweb.org/wiki/index.php?title=Material