* \brief Sets the type of values in the field
*/
void SetValuesType(in short theType);
+ /*!
+ * \brief Returns the type of values in the field
+ */
+ short GetValuesType();
/*!
* \brief Sets the list of time step IDs in the field
anObj = salome.orb.string_to_object(anIOR)
if type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Group:
if len(aResult):
- aResult = aResult + '|'
+ aResult += '|'
# store internal entry, type and list of indices of the group selection (separated by spaces)
- aResult = aResult + anObj.GetEntry() + "|" + str(anObj.GetSelectionType())
+ aResult += anObj.GetEntry() + "|" + str(anObj.GetSelectionType())
aSelList = anObj.GetSelection()
- aResult = aResult + "|" + str(' '.join(str(anI) for anI in aSelList))
+ aResult += "|" + str(' '.join(str(anI) for anI in aSelList))
elif type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Field:
if len(aResult):
- aResult = aResult + '|'
+ aResult += '|'
# same as for group, but in addition to the second string part - field specifics
- aResult = aResult + anObj.GetEntry() + "|" + str(anObj.GetSelectionType())
- aResult = aResult + " " + str(anObj.GetDataType()) # values type
+ aResult += anObj.GetEntry() + "|" + str(anObj.GetSelectionType())
+ aResult += " " + str(anObj.GetDataType()) # values type
aSteps = anObj.GetSteps()
- aResult = aResult + " " + str(len(aSteps)) # number of steps
+ aResult += " " + str(len(aSteps)) # number of steps
aComps = anObj.GetComponents()
- aResult = aResult + " " + str(len(aComps)) # number of components
+ aResult += " " + str(len(aComps)) # number of components
for aComp in aComps: # components strings: but before remove spaces and '|'
aCoded = aComp.replace(" ", "__space__").replace("|", "__vertical_bar__")
- aResult = aResult + " " + aCoded
+ aResult += " " + aCoded
for aStepNum in range(len(aSteps)):
aVals = anObj.GetStep(aStepNum + 1).GetValues()
if aStepNum == 0:
- aResult = aResult + " " + str(len(aVals)) # first the number of values in the step
- aResult = aResult + " " + str(anObj.GetStep(aStepNum + 1).GetStamp()) # ID of stamp in step
+ aResult += " " + str(len(aVals)) # first the number of values in the step
+ aResult += " " + str(anObj.GetStep(aStepNum + 1).GetStamp()) # ID of stamp in step
for aVal in aVals:
- aResult = aResult + " " + str(aVal) # all values of step
+ aResult += " " + str(aVal) # all values of step
aSelList = anObj.GetSelection()
- aResult = aResult + "|" + str(' '.join(str(anI) for anI in aSelList))
+ aResult += "|" + str(' '.join(str(anI) for anI in aSelList))
elif isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
if len(aResult):
- aResult = aResult + '|'
+ aResult += '|'
# store internal entry, current and old shapes in BRep format
- aResult = aResult + anObj.GetEntry() + "|" + anObj.GetShapeStream().decode()
- aResult = aResult + "|" + anObj.GetOldShapeStream().decode()
+ aResult += anObj.GetEntry() + "|" + anObj.GetShapeStream().decode()
+ aResult += "|" + anObj.GetOldShapeStream().decode()
return aResult.encode()
# to avoid spaces and parenthesis in the variable name
aBaseName = theBaseName.replace(" ", "_").replace("(", "").replace(")", "")
aName = aBaseName
- while aName in __entry2DumpName__:
+ while aName in __entry2DumpName__.values():
aName = aBaseName + "_" + str(aPrefix)
aPrefix = aPrefix + 1
__entry2DumpName__[theID] = aName
aShapeVar = self.UniqueDumpName(anObj.GetName(), anObj.GetSO().GetID())
aShapeStr = aShapeVar + ", "
for aGName in aGroupVarNames:
- aShapeStr = aShapeStr + aGName + ", "
- aShapeStr = aShapeStr + "= SHAPERSTUDY.shape(\"" + anObj.GetEntry() +"\")"
+ aShapeStr += aGName + ", "
+ aShapeStr += "= SHAPERSTUDY.shape(\"" + anObj.GetEntry() +"\")"
script.append(aShapeStr)
# dump also dead-shapes with groups and fields in the XAO format
aRes, aHistSO = aShapeObj.GetSO().FindSubObject(2) # the History folder
aXAO = StudyData_Swig.StudyData_XAO()
aXAO.SetShape(aDeadShape.getShape())
anArchiveName = "archive_" + str(anArchiveNum) + ".xao"
- anArchiveNum = anArchiveNum + 1
+ anArchiveNum += 1
aDeadVarName = self.UniqueDumpName(aDeadShape.GetName(), aDSO.GetID())
- aDeadString = aDeadString + aDeadVarName + ", "
+ aDeadString += aDeadVarName + ", "
aDGroupIter = aStudy.NewChildIterator(aDSO)
+
while aDGroupIter.More():
aDeadGroup = aDGroupIter.Value().GetObject()
if isinstance(aDeadGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
aDGroupVarName = self.UniqueDumpName(aDeadGroup.GetName(), aDGroupIter.Value().GetID())
- aDeadString = aDeadString + aDGroupVarName + ", "
+ aDeadString += aDGroupVarName + ", "
aGroupID = aXAO.AddGroup(aDeadGroup.GetSelectionType(), aDGroupVarName)
for aSel in aDeadGroup.GetSelection():
aXAO.AddGroupSelection(aGroupID, aSel)
+ elif isinstance(aDeadGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
+ aDeadField = aDeadGroup
+ aDFieldVarName = self.UniqueDumpName(aDeadField.GetName(), aDGroupIter.Value().GetID())
+ aDeadString += aDFieldVarName + ", "
+ aComponents = aDeadField.GetComponents()
+ aFieldID = aXAO.AddField(aDeadField.GetValuesType(), aDeadField.GetSelectionType(), \
+ len(aComponents), aDFieldVarName)
+ for aCompIndex in range(len(aComponents)):
+ aXAO.SetFieldComponent(aFieldID, aCompIndex, aComponents[aCompIndex])
+ aSteps = aDeadField.GetSteps()
+ for aStep in aSteps:
+ aFieldStep = aDeadField.GetStep(aStep)
+ aXAO.AddStep(aFieldID, aStep, aFieldStep.GetStamp())
+ aStepVals = aFieldStep.GetValues()
+ for aValue in aStepVals:
+ aXAO.AddStepValue(aFieldID, aStep, str(aValue))
aDGroupIter.Next()
aXAO.Export(anArchiveName)
- aDeadString = aDeadString + " = SHAPERSTUDY.archive(" + aShapeVar + ", \"" + anArchiveName + "\")"
+ aDeadString += " = SHAPERSTUDY.archive(" + aShapeVar + ", \"" + anArchiveName + "\")"
script.append(aDeadString)
aDeads.Next()
pass
aRes = (aDShape,)
# add groups and fields to the result
aGroupIndex = 0
+ aFieldIndex = 0
aSOIter = aStudy.NewChildIterator(aLastDeadSO)
while aSOIter.More():
aGroupSO = aSOIter.Value()
if len(anIOR):
aGroup = salome.orb.string_to_object(anIOR)
if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
- aRes = aRes + (aGroup,)
+ aRes += (aGroup,)
aGroup.SetSelectionType(aXAO.GetGroupDimension(aGroupIndex))
aSelection = []
for aSel in aXAO.GetGroupSelection(aGroupIndex):
aSelection.append(aSel)
aGroup.SetSelection(aSelection)
- aGroupIndex = aGroupIndex + 1
+ aGroupIndex += 1
elif isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
- aRes = aRes + (aGroup,)
+ aField = aGroup
+ aRes += (aField,)
+ aField.SetValuesType(aXAO.GetValuesType(aFieldIndex))
+ aField.SetSelectionType(aXAO.GetSelectionType(aFieldIndex))
+ aField.SetComponents(aXAO.GetComponents(aFieldIndex))
+ aField.ClearFieldSteps()
+ for aStepIndex in range(aXAO.GetStepsNum(aFieldIndex)):
+ aField.AddFieldStep(aXAO.GetStamp(aFieldIndex, aStepIndex), \
+ aXAO.GetStepIndex(aFieldIndex, aStepIndex), \
+ aXAO.GetValues(aFieldIndex, aStepIndex))
+ aFieldIndex += 1
aSOIter.Next()
return aRes
return None # not found
aDeadSO = aBuilder.NewObject(aHistSO)
anIndex = aDeadSO.Tag()
aDeadSO.SetAttrString("AttributeName", self.SO.GetName() + " (" + str(anIndex) + ")")
+ aRes, aPixMap = aBuilder.FindAttribute(self.SO, "AttributePixMap")
+ if aRes:
+ aDeadPixMap = aBuilder.FindOrCreateAttribute(aDeadSO, "AttributePixMap")
+ aDeadPixMap.SetPixMap(aPixMap.GetPixMap())
aDead = SHAPERSTUDY_Object()
aDeadEntry = "dead" + str(anIndex) + "_" + self.GetEntry()
aDead.SetEntry(aDeadEntry)
anIOR = aGroupSO.GetIOR()
if len(anIOR):
aGroup = salome.orb.string_to_object(anIOR)
- if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
- aDeadGroup = SHAPERSTUDY_Group()
+ if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
+ isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
+ if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
+ aDeadGroup = SHAPERSTUDY_Group()
+ else:
+ aDeadGroup = SHAPERSTUDY_Field()
aDeadGroupEntry = "dead" + str(anIndex) + "_" + aGroup.GetEntry()
aDeadGroup.SetEntry(aDeadGroupEntry)
- aDeadGroup.SetShapeByPointer(aGroup.getShape())
aDeadGroup.SetSelectionType(aGroup.GetSelectionType())
aDeadGroup.SetSelection(aGroup.GetSelection())
+ if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field): # additional field data
+ aDeadGroup.SetValuesType(aGroup.GetValuesType())
+ aDeadGroup.SetSteps(aGroup.GetSteps())
+ aDeadGroup.SetComponents(aGroup.GetComponents())
+ for aStep in aGroup.GetSteps():
+ aStepObj = aGroup.GetStep(aStep)
+ aDeadGroup.AddFieldStep(aStepObj.GetStamp(), aStep, aStepObj.GetValues())
aDeadGroupSO = aBuilder.NewObject(aDeadSO)
aDeadGroup.SetSO(aDeadGroupSO)
# 15.01.20 groups and fields names stays the same
#aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName())
+ aRes, aPixMap = aBuilder.FindAttribute(aGroupSO, "AttributePixMap")
+ if aRes:
+ aDeadPixMap = aBuilder.FindOrCreateAttribute(aDeadGroupSO, "AttributePixMap")
+ aDeadPixMap.SetPixMap(aPixMap.GetPixMap())
aDeadGroupObj = aDeadGroup._this()
anIOR = salome.orb.object_to_string(aDeadGroupObj)
aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
"""
self.valtype = theType
+ def GetValuesType( self ):
+ """
+ Returns the type of values in the field
+ """
+ return self.valtype
+
+
def GetDataType( self ):
"""
Returns the type of values in the field in terms of GEOM enumeration
#include <XAO_BrepGeometry.hxx>
-StudyData_XAO::StudyData_XAO() : myExport(NULL), myImport(NULL)
+StudyData_XAO::StudyData_XAO() : myExport(NULL), myImport(NULL), myCurrentElementID(0)
{}
void StudyData_XAO::SetShape(const long long theShapePtr)
aGeometry->setTopoDS_Shape(*myShape);
}
-int StudyData_XAO::AddGroup(const int theSelType, const std::string theGroupName)
-{
- if (!myExport)
- myExport = new XAO::Xao();
- XAO::Dimension aDimension;
+static XAO::Dimension GetDimension(const int theSelType) {
switch(theSelType) {
- case 7: aDimension = XAO::VERTEX; break;
- case 6: aDimension = XAO::EDGE; break;
- case 4: aDimension = XAO::FACE; break;
- case 2: aDimension = XAO::SOLID; break;
- default: aDimension = XAO::WHOLE;
+ case 7: return XAO::VERTEX;
+ case 6: return XAO::EDGE;
+ case 4: return XAO::FACE;
+ case 2: return XAO::SOLID;
+ default: return XAO::WHOLE;
};
- XAO::Group* aNewGroup = myExport->addGroup(aDimension, theGroupName);
+ return XAO::WHOLE;
+}
+
+int StudyData_XAO::AddGroup(const int theSelType, const std::string theGroupName)
+{
+ XAO::Group* aNewGroup = myExport->addGroup(GetDimension(theSelType), theGroupName);
int anID = (int)myGroups.size();
myGroups[anID] = aNewGroup;
return anID;
void StudyData_XAO::Export(const std::string theFileName)
{
- if (!myExport)
- myExport = new XAO::Xao();
myExport->setAuthor("ShaperStudy");
XAO::XaoExporter::saveToFile(myExport, theFileName, "");
}
+int StudyData_XAO::AddField(const int theValType, const int theSelType,
+ const int theCompsNum, const std::string theFieldName)
+{
+ XAO::Field* aNewField = myExport->addField(
+ XAO::Type(theValType), GetDimension(theSelType), theCompsNum, theFieldName);
+ int anID = (int)myFields.size();
+ myFields[anID] = aNewField;
+ return anID;
+}
+
+void StudyData_XAO::SetFieldComponent(const int theFieldID, const int theCompIndex,
+ const std::string theCompName)
+{
+ myFields[theFieldID]->setComponentName(theCompIndex, theCompName);
+}
+
+void StudyData_XAO::AddStep(const int theFieldID, const int theStepID, const int theStampID)
+{
+ XAO::Step* aNewStep = myFields[theFieldID]->addNewStep(theStepID);
+ aNewStep->setStamp(theStampID);
+ if (mySteps.find(theFieldID) == mySteps.end())
+ mySteps[theFieldID] = std::map<int, XAO::Step*>();
+ mySteps[theFieldID][theStepID] = aNewStep;
+ myCurrentElementID = 0;
+}
+
+void StudyData_XAO::AddStepValue(
+ const int theFieldID, const int theStepID, std::string theValue)
+{
+ int aColumns = myFields[theFieldID]->countComponents();
+ mySteps[theFieldID][theStepID]->setStringValue(
+ myCurrentElementID / aColumns, myCurrentElementID % aColumns, theValue);
+ myCurrentElementID++;
+}
+
std::string StudyData_XAO::Import(const std::string theFileName)
{
std::string anError;
return (long long)(myShape);
}
-int StudyData_XAO::GetGroupDimension(const int theGroupID)
-{
- XAO::Group* aXaoGroup = myImport->getGroup(theGroupID);
- switch(aXaoGroup->getDimension()) {
+static int GetSelectionType(const XAO::Dimension theDimension) {
+ switch(theDimension) {
case XAO::VERTEX: return 7;
case XAO::EDGE: return 6;
case XAO::FACE: return 4;
return -1;
}
+int StudyData_XAO::GetGroupDimension(const int theGroupID)
+{
+ XAO::Group* aXaoGroup = myImport->getGroup(theGroupID);
+ return GetSelectionType(aXaoGroup->getDimension());
+}
+
std::list<long> StudyData_XAO::GetGroupSelection(const int theGroupID)
{
XAO::Group* aXaoGroup = myImport->getGroup(theGroupID);
}
return aResult;
}
+
+int StudyData_XAO::GetValuesType(const int theFieldID)
+{
+ XAO::Field* aField = myImport->getField(theFieldID);
+ return (int)(aField->getType());
+}
+
+int StudyData_XAO::GetSelectionType(const int theFieldID)
+{
+ XAO::Field* aField = myImport->getField(theFieldID);
+ return GetSelectionType(aField->getDimension());
+}
+
+std::list<std::string> StudyData_XAO::GetComponents(const int theFieldID)
+{
+ XAO::Field* aField = myImport->getField(theFieldID);
+ std::list<std::string> aResult;
+ int aNum = aField->countComponents();
+ for(int a = 0; a < aNum; a++) {
+ aResult.push_back(aField->getComponentName(a));
+ }
+ return aResult;
+}
+
+void StudyData_XAO::BeginSteps(const int theFieldID)
+{
+ myStepIterator = myImport->getField(theFieldID)->begin();
+}
+
+bool StudyData_XAO::More(const int theFieldID)
+{
+ return myStepIterator != myImport->getField(theFieldID)->end();
+}
+
+void StudyData_XAO::Next()
+{
+ myStepIterator++;
+}
+
+int StudyData_XAO::GetStamp()
+{
+ return (*myStepIterator)->getStamp();
+}
+
+int StudyData_XAO::GetStepIndex()
+{
+ return (*myStepIterator)->getStep();
+}
+
+std::list<std::string> StudyData_XAO::GetValues()
+{
+ std::list<std::string> aResult;
+ int aComps = (*myStepIterator)->countComponents();
+ int aVals = (*myStepIterator)->countValues();
+ for(int a = 0; a < aVals; a++) {
+ aResult.push_back((*myStepIterator)->getStringValue(a / aComps, a % aComps));
+ }
+
+ return aResult;
+}
#include "StudyData.h"
#include <XAO_Xao.hxx>
+#include <XAO_Step.hxx>
+#include <XAO_Field.hxx>
#include <list>
#include <map>
XAO::Xao* myExport; ///< the XAO instance for export
XAO::Xao* myImport; ///< the XAO instance for export
std::map<int, XAO::Group*> myGroups; ///< id of group to the group structure
+ std::map<int, XAO::Field*> myFields; ///< id of field to the field structure
+ std::map<int, std::map<int, XAO::Step*> > mySteps; ///< id of field to the field structure
+ int myCurrentElementID; ///< to add elements of step one by one
+ XAO::stepIterator myStepIterator; ///< contains a current steps iterator (on import)
public:
StudyData_EXPORT StudyData_XAO();
// sets the selection for an already added group
StudyData_EXPORT void AddGroupSelection(const int theGroupID, const int theSelection);
+ // add a new field for export to XAO; returns id of this field
+ StudyData_EXPORT int AddField(const int theValType, const int theSelType,
+ const int theCompsNum, const std::string theFieldName);
+ // set the component name for the exported field
+ StudyData_EXPORT void SetFieldComponent(const int theFieldID, const int theCompIndex,
+ const std::string theCompName);
+ // adds a step to the exported field
+ StudyData_EXPORT void AddStep(const int theFieldID, const int theStepID, const int theStampID);
+ // adds the value to the step of the exported field. values must come one by one (row by row)
+ StudyData_EXPORT void AddStepValue(
+ const int theFieldID, const int theStepID, std::string theValue);
+
// performs the export to XAO
StudyData_EXPORT void Export(const std::string theFileName);
// Returns a selection list of indices of the group
StudyData_EXPORT std::list<long> GetGroupSelection(const int theGroupID);
+
+ // Returns a value type of the imported field
+ StudyData_EXPORT int GetValuesType(const int theFieldID);
+ // Returns a selection type of the imported field
+ StudyData_EXPORT int GetSelectionType(const int theFieldID);
+ // Returns components names of the imported field
+ StudyData_EXPORT std::list<std::string> GetComponents(const int theFieldID);
+ // Starts iteration of steps
+ StudyData_EXPORT void BeginSteps(const int theFieldID);
+ // Returns true if steps iteration contains a current step
+ StudyData_EXPORT bool More(const int theFieldID);
+ // Iterates the step iterator contains a current step
+ StudyData_EXPORT void Next();
+ // Returns a stamp ID of the imported field step
+ StudyData_EXPORT int GetStamp();
+ // Returns a step ID of the imported field step
+ StudyData_EXPORT int GetStepIndex();
+ // Returns string values of the imported field step
+ StudyData_EXPORT std::list<std::string> GetValues();
};
#endif // !StudyData_XAO_H