Commit 9e60da39 authored by promayon's avatar promayon
Browse files

NEW multiComponent can now hold a custom list of properties as well...

NEW multiComponent can now hold a custom list of properties as well (test/customProperty-example.pml updated to unit test this new feature) (first PML new feature since ages!)
FIXED remove unneeded space in xml ouput

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@124 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 89258caf
......@@ -157,11 +157,11 @@ void BasicAtomProperties::setPositionPointer(double * ptr, bool update) {
//----------------------- beginXML -----------------------
void BasicAtomProperties::beginXML(std::ostream & o) {
o << "<atomProperties index=\"" << index << "\" ";
o << "x=\"" << X[0] << "\" y=\"" << X[1] << "\" z=\"" << X[2] << "\" ";
o << "<atomProperties index=\"" << index << "\"";
o << " x=\"" << X[0] << "\" y=\"" << X[1] << "\" z=\"" << X[2] << "\"";
if (getName() != "")
o << "name=\"" << getName().c_str() << "\" ";
o << " name=\"" << getName().c_str() << "\" ";
}
//----------------------- endXML -----------------------
......
......@@ -93,52 +93,50 @@ BasicCellProperties::BasicCellProperties(PhysicalModel *p, const StructureProper
/// write the default xml properties (beginning)
void BasicCellProperties::beginXML(std::ostream & o) {
o << "<cellProperties index=\"" << index << "\" ";
o << "<cellProperties index=\"" << index << "\"";
// print the type
switch (getType()) {
case StructureProperties::TETRAHEDRON:
o << "type=\"TETRAHEDRON\" ";
o << " type=\"TETRAHEDRON\"";
break;
case StructureProperties::HEXAHEDRON:
o << "type=\"HEXAHEDRON\" ";
o << " type=\"HEXAHEDRON\"";
break;
case StructureProperties::WEDGE:
o << "type=\"WEDGE\" ";
o << " type=\"WEDGE\"";
break;
case StructureProperties::POLY_LINE:
o << "type=\"POLY_LINE\" ";
o << " type=\"POLY_LINE\"";
break;
case StructureProperties::POLY_VERTEX:
o << "type=\"POLY_VERTEX\" ";
o << " type=\"POLY_VERTEX\"";
break;
case StructureProperties::LINE:
o << "type=\"LINE\" ";
o << " type=\"LINE\"";
break;
case StructureProperties::TRIANGLE:
o << "type=\"TRIANGLE\" ";
o << " type=\"TRIANGLE\"";
break;
case StructureProperties::QUAD:
o << "type=\"QUAD\" ";
o << " type=\"QUAD\"";
break;
default:
o << "type=\"???\" ";
o << " type=\"???\"";
break;
}
o << " ";
if (getName() != "")
o << "name=\"" << getName().c_str() << "\" ";
o << " name=\"" << getName().c_str() << "\" ";
}
......
......@@ -392,11 +392,11 @@ inline void BasicSCProperties::setVisible(const RenderingMode::Mode m, const boo
inline void BasicSCProperties::beginXML(std::ostream & o) {
// print the name if there is one
if (getName() != "")
o << " name=\"" << getName().c_str() << "\" ";
o << " name=\"" << getName().c_str() << "\"";
// the mode property (if different than default)
if (mode.getMode() != RenderingMode::NONE) {
o << " mode=\"" << mode.getModeString() << "\" ";
o << " mode=\"" << mode.getModeString() << "\"";
}
}
......
......@@ -48,6 +48,7 @@ public:
* If not given name is initialized to the empty string
*/
Component(PhysicalModel *, std::string n="");
/** Virtual destructor needed here as this is an abstract class (pure virtual) */
virtual ~Component();
......@@ -107,8 +108,11 @@ public:
/// get the physical model
PhysicalModel * getPhysicalModel() const;
/// get the component structural properties (guarantied to be non NULL)
Properties* getProperties();
protected:
Properties *properties;
Properties* properties;
/** this tell the parent components that this component is
* removed from memory.
......@@ -175,4 +179,9 @@ inline PhysicalModel * Component::getPhysicalModel() const {
return properties->getPhysicalModel();
}
inline Properties* Component::getProperties() {
return properties;
}
#endif //COMPONENT_H
......@@ -56,7 +56,12 @@ void MultiComponent::xmlPrint(std::ostream &o) const {
if (getNumberOfSubComponents()>0) {
o << "<multiComponent";
if (getName() != "")
o<< " name=\"" << getName().c_str() << "\" ";
o<< " name=\"" << getName().c_str() << "\"";
// print extra properties
for(unsigned int i=0;i<properties->numberOfFields();i++)
o << " "<< properties->getField(i) << "=\"" << properties->getString(properties->getField(i)) << "\"";
o << ">" << std::endl;
for (unsigned int i=0; i<components.size(); i++) {
components[i]->xmlPrint(o);
......
......@@ -89,12 +89,12 @@ void PhysicalModel::clear() {
informativeComponents = NULL;
if ( exclusiveComponents )
if ( exclusiveComponents )
delete exclusiveComponents;
exclusiveComponents = NULL;
exclusiveComponents = NULL;
// clean position memory
// clean position memory
delete positionPtr;
......@@ -360,7 +360,7 @@ bool PhysicalModel::parseTree ( xmlNodePtr root ) {
positionPtr = new double[3*atoms->getNumberOfStructures() ];
// assign all position memory
double * currentPositionPtr = positionPtr;
for ( unsigned int i=0;i<atoms->getNumberOfStructures();i++ ) {
for ( unsigned int i=0; i<atoms->getNumberOfStructures(); i++ ) {
Atom *a = dynamic_cast<Atom *> ( atoms->getStructure ( i ) );
a->getProperties()->setPositionPointer ( currentPositionPtr );
// next position => jump 3 double memory space
......@@ -399,6 +399,24 @@ bool PhysicalModel::parseTree ( xmlNodePtr root ) {
mc->setName ( std::string ( ( char* ) pname ) );
xmlFree ( pname );
// parse extra properties to fill the property fields map
xmlAttr * attrs = mcNode->properties;
xmlNodePtr unknownAttrs = xmlNewNode(NULL, (xmlChar*)("unknownAttrs"));;
while (attrs) {
const xmlChar * pname = attrs->name;
xmlChar * pval = attrs->children->content;
if (pname && xmlStrcmp(pname, (xmlChar*)"name")) {
xmlSetProp(unknownAttrs, pname, pval);
}
attrs = attrs->next;
}
//transform the unknown attributes to a property field map
mc->getProperties()->domToFields(unknownAttrs);
xmlFreeNode(unknownAttrs);
parseComponents ( mcNode, mc, true );
......@@ -490,13 +508,30 @@ bool PhysicalModel::parseComponents ( xmlNodePtr root, Component * father, bool
MultiComponent * mc = new MultiComponent ( this );
mc->setExclusive ( isExclusive );
// parse the name
xmlChar *pname = xmlGetProp ( child, ( const xmlChar* ) "name" );
if ( pname )
mc->setName ( std::string ( ( char* ) pname ) );
xmlFree ( pname );
// parse extra properties to fill the property fields map
xmlAttr * attrs = child->properties;
xmlNodePtr unknownAttrs = xmlNewNode(NULL, (xmlChar*)("unknownAttrs"));;
while (attrs) {
const xmlChar * pname = attrs->name;
xmlChar * pval = attrs->children->content;
if (pname && xmlStrcmp(pname, (xmlChar*)"name")) {
xmlSetProp(unknownAttrs, pname, pval);
}
attrs = attrs->next;
}
//transform the unknown attributes to a property field map
mc->getProperties()->domToFields(unknownAttrs);
xmlFreeNode(unknownAttrs);
( ( MultiComponent* ) father )->addSubComponent ( mc );
//parse the multicomponent subtree
......@@ -644,7 +679,7 @@ void PhysicalModel::setAtoms ( StructuralComponent *sc, bool deleteOld ) {
atoms = sc;
// register all the atoms in the map, and tell the atoms about its new status
for ( unsigned int i = 0; i < sc->getNumberOfStructures();i++ ) {
for ( unsigned int i = 0; i < sc->getNumberOfStructures(); i++ ) {
a = ( Atom * ) sc->getStructure ( i );
a->getProperties()->setPhysicalModel ( this );
addGlobalIndexAtomPair ( std::GlobalIndexStructurePair ( a->getIndex(), a ) );
......
......@@ -30,31 +30,31 @@ $CAMITK_LICENCE_END$
void AtomProperties::init() {
myCustomProperty1 = 10;
myCustomProperty2 = "no name";
}
//--------------- destructor --------------
AtomProperties::~AtomProperties() {
}
// --------------- xmlPrint ---------------
void AtomProperties::xmlPrint(std::ostream &o) {
// beginning of the atom properties
beginXML(o);
for(std::map<std::string, std::string>::iterator it = fields.begin(); it!=fields.end() ; it++)
o << " "<<(*it).first<<"=\"" <<(*it).second<< "\" ";
// print the custom properties only if different than default value
if (myCustomProperty1 != 10) {
o << " myCustomProperty1=\"" << myCustomProperty1 << "\" ";
}
if (myCustomProperty2 != "no name") {
o << " myCustomProperty2=\"" << myCustomProperty2 << "\" ";
}
// end of the properties
endXML(o);
// beginning of the atom properties
beginXML(o);
for(std::map<std::string, std::string>::iterator it = fields.begin(); it!=fields.end() ; it++)
o << " "<<(*it).first<<"=\"" <<(*it).second<< "\"";
// print the custom properties only if different than default value
if (myCustomProperty1 != 10) {
o << " myCustomProperty1=\"" << myCustomProperty1 << "\"";
}
if (myCustomProperty2 != "no name") {
o << " myCustomProperty2=\"" << myCustomProperty2 << "\"";
}
// end of the properties
endXML(o);
}
......@@ -30,31 +30,31 @@ $CAMITK_LICENCE_END$
void CellProperties::init() {
myCustomProperty1 = 0.0;
myCustomProperty2 = 0;
}
//--------------- destructor --------------
CellProperties::~CellProperties() {
}
// --------------- xmlPrint ---------------
void CellProperties::xmlPrint(std::ostream &o) {
// beginning of the atom properties
beginXML(o);
for(std::map<std::string, std::string>::iterator it = fields.begin(); it!=fields.end() ; it++)
o << " "<<(*it).first<<"=\"" <<(*it).second<< "\" ";
// print the custom properties only if different than default value
if (myCustomProperty1 != 0.0) {
o << " myCustomProperty1=\"" << myCustomProperty1 << "\" ";
}
if (myCustomProperty2 != 0) {
o << " myCustomProperty2=\"" << myCustomProperty2 << "\" ";
}
// end of the properties
endXML(o);
// beginning of the atom properties
beginXML(o);
for(std::map<std::string, std::string>::iterator it = fields.begin(); it!=fields.end() ; it++)
o << " "<<(*it).first<<"=\"" <<(*it).second<< "\"";
// print the custom properties only if different than default value
if (myCustomProperty1 != 0.0) {
o << " myCustomProperty1=\"" << myCustomProperty1 << "\"";
}
if (myCustomProperty2 != 0) {
o << " myCustomProperty2=\"" << myCustomProperty2 << "\"";
}
// end of the properties
endXML(o);
}
......@@ -30,31 +30,32 @@ $CAMITK_LICENCE_END$
void StructuralComponentProperties::init() {
myCustomProperty1 = 0;
myCustomProperty2 = "~";
}
//--------------- destructor --------------
StructuralComponentProperties::~StructuralComponentProperties() {
}
// --------------- xmlPrint ---------------
void StructuralComponentProperties::xmlPrint(std::ostream &o) {
// beginning of the atom properties
beginXML(o);
for(std::map<std::string, std::string>::iterator it = fields.begin(); it!=fields.end() ; it++)
o << " "<<(*it).first<<"=\"" <<(*it).second<< "\" ";
// print the custom properties only if different than default value
if (myCustomProperty1 != 0) {
o << " myCustomProperty1=\"" << myCustomProperty1 << "\" ";
}
if (myCustomProperty2 != "~") {
o << " myCustomProperty2=\"" << myCustomProperty2 << "\" ";
}
// end of the properties
endXML(o);
// beginning of the SC properties
beginXML(o);
// print all fields
for(std::map<std::string, std::string>::iterator it = fields.begin(); it!=fields.end() ; it++)
o << " "<<(*it).first<<"=\"" <<(*it).second<< "\"";
// print the custom properties only if different than default value
if (myCustomProperty1 != 0) {
o << " myCustomProperty1=\"" << myCustomProperty1 << "\"";
}
if (myCustomProperty2 != "~") {
o << " myCustomProperty2=\"" << myCustomProperty2 << "\"";
}
// end of the properties
endXML(o);
}
......@@ -40,19 +40,21 @@ class Object3D;
#include <string>
/** A structural component is composed either by cell or by atoms.
*
*
*/
class StructuralComponent : public Component {
public:
/** Default Constructor.
*/
StructuralComponent(PhysicalModel *);
/** constructor from xml node: try to read and get the parmaters from xml */
StructuralComponent(PhysicalModel *, xmlNodePtr);
/** constructor from xml node: try to read and get the parmaters from xml */
StructuralComponent(PhysicalModel *, xmlNodePtr);
/** constructor that allows to name the structure.
*/
StructuralComponent(PhysicalModel *, std::string);
/// delete all the structures (call the deleteAllStructures method)
virtual ~StructuralComponent();
......@@ -76,12 +78,12 @@ public:
*/
bool addStructureIfNotIn(Structure *s);
/** Check if a given structure is present in the list
/** Check if a given structure is present in the list
* @param s the structure to check
* @return true if and only if the structure is already in the list
*/
bool isStructureIn(Structure *s);
/**
* Remove a structure from the list (and tells the structure to remove this structural
* component from its list).
......@@ -111,7 +113,7 @@ public:
* get a structure by its unique index
*/
Structure * getStructureByIndex(const unsigned int);
/** print to an output stream in "pseudo" XML format (do nothing if there are no sub structures).
*/
void xmlPrint(std::ostream &) const;
......@@ -185,8 +187,8 @@ public:
void plannedNumberOfStructures(const unsigned int);
/// set the physical model (recursively to all cells or to all atoms)
virtual void setPhysicalModel(PhysicalModel *);
virtual void setPhysicalModel(PhysicalModel *);
protected:
/**
* List of the structure representing this component, all the structure in this list are either all Atom or all Cell (no mix!)
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- physical model is a generic representation for 3D physical model (FEM, spring mass network, Phymulob...)
- Testing custom properties (pml v0.7 and over):
- 1) just read this file!
......@@ -14,47 +15,46 @@
-->
<physicalModel name="custom physical properties test" nrOfAtoms="8"
nrOfExclusiveComponents="1"
nrOfInformativeComponents="0"
nrOfCells="1"
>
<!-- list of atoms: -->
<atoms>
<structuralComponent name="atom list" >
<structuralComponent name="atom list">
<nrOfStructures value="8"/>
<atom>
<atomProperties index="0" x="-5" y="5" z="-5" name="a0" atomIntProp="-103" />
<atomProperties index="0" x="-5" y="5" z="-5" name="a0" atomIntProp="-103"/>
</atom>
<atom>
<atomProperties index="1" x="5" y="5" z="-5" atomStringProp="a string property!" />
<atomProperties index="1" x="5" y="5" z="-5" atomStringProp="a string property!"/>
</atom>
<atom>
<atomProperties index="2" x="5" y="5" z="5" AtomUIntProp="141304" />
<atomProperties index="2" x="5" y="5" z="5" AtomUIntProp="141304"/>
</atom>
<atom>
<atomProperties index="3" x="-5" y="5" z="5" aToMdOuBlEpRoP="-155.34" />
<atomProperties index="3" x="-5" y="5" z="5" aToMdOuBlEpRoP="-155.34"/>
</atom>
<atom>
<atomProperties index="4" x="-5" y="-5" z="-5" atomStringProp="same string property!" aToMdOuBlEpRoP="4.88801" />
<atomProperties index="4" x="-5" y="-5" z="-5" aToMdOuBlEpRoP="4.88801" atomStringProp="same string property!"/>
</atom>
<atom>
<atomProperties index="5" x="5" y="-5" z="-5" />
<atomProperties index="5" x="5" y="-5" z="-5"/>
</atom>
<atom>
<atomProperties index="6" x="5" y="-5" z="5" />
<atomProperties index="6" x="5" y="-5" z="5"/>
</atom>
<atom>
<atomProperties index="7" x="-5" y="-5" z="5" />
<atomProperties index="7" x="-5" y="-5" z="5"/>
</atom>
</structuralComponent>
</atoms>
<!-- list of exclusive components : -->
<exclusiveComponents>
<multiComponent name="Exclusive components" >
<structuralComponent name="One SC" mode="WIREFRAME_AND_SURFACE" scBoolProp="1" scCharProp="$" >
<multiComponent name="Exclusive components" evenHere="it works!" globalToMulticomponent="yes">
<structuralComponent name="One SC" mode="WIREFRAME_AND_SURFACE" scBoolProp="1" scCharProp="$">
<color r="0.8" g="0.8" b="0.2" a="1" />
<nrOfStructures value="1"/>
<cell>
<cellProperties index="0" type="HEXAHEDRON" name="cell property test" cellFloatProp="100.256" cellIntProp="4" scBoolProp="1" scCharProp="@" />
<cellProperties index="0" type="HEXAHEDRON" name="cell property test" cellFloatProp="100.256" cellIntProp="4" scBoolProp="1" scCharProp="@"/>
<nrOfStructures value="8"/>
<atomRef index="0" />
<atomRef index="1" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment