To export results without joining them into compound. In this case group that contains selection on several results must be splitted into several groups (with same name), located under the corresponding results.
@SET SHAPER_ROOT_DIR=%ROOT_DIR%\install
@SET SalomeAppConfig=%SHAPER_ROOT_DIR%\share\salome\resources\shaper;%GUI_ROOT_DIR%\share\salome\resources\gui
-start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" %*
+start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" --modules=SHAPER,GEOM,SMESH %*
{
AttributeSelectionListPtr aSelList =
theFeature->selectionList(CollectionPlugin_Field::SELECTED_ID());
+ std::string aTypeStr = aSelList->selectionType();
+ if (aTypeStr == "part")
+ return true;
if (aSelList->isInitialized()) {
int aSize = aSelList->size();
- std::string aTypeStr = aSelList->selectionType();
- if (aTypeStr == "part")
- return true;
- else {
- bool aIsDefined = aSize > 0;
- if (!aIsDefined)
- theError = "Selection list is not initialized";
- return aIsDefined;
- }
+ bool aIsDefined = aSize > 0;
+ if (!aIsDefined)
+ theError = "Selection list is not initialized";
+ return aIsDefined;
}
theError = "Selection list is not initialized";
return false;
Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Translation_1_1"), model.selection("SOLID", "Box_2_1")])
Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Box_2_1/Top")])
model.do()
- model.end()
# First export to GEOM
model.exportToGEOM(Part_1_doc)
+ model.end()
# Check that the GEOM object has 1 compsolid and 2 solids
geomObject_1 = getLastGEOMShape()
assert geompy.NumberOfFaces(geomGroup_1) == 2
# Add a third box
+ model.begin()
Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 20)
+ model.do()
# Second export to GEOM
model.exportToGEOM(Part_1_doc)
+ model.end()
- # Check that the GEOM object has 3 solids
+ # Check that the last exported GEOM object is 1 solids
geomObject_2 = getLastGEOMShape()
- assert geompy.NumberOfSolids(geomObject_2) == 3
+ assert geompy.NumberOfSolids(geomObject_2) == 1
# Dump the salome study (only CORBA modules, SHAPER dump is not in it)
tempdir = tempfile.gettempdir()
Field_4 = model.addField(Part_1_doc, 1, "DOUBLE", 1, ["Comp 1"], Field_4_objects)
Field_4.result().setName("Field_vertices")
Field_4.addStep(0, 0, [[0], [1], [1], [1], [1], [1], [1], [1], [1], [2], [2], [2], [2], [3], [3], [3], [3]])
- model.exportToGEOM(Part_1_doc)
model.do()
+ model.exportToGEOM(Part_1_doc)
model.end()
# check the groups content by the coordinates of a point on its sub-shapes
## Check the result imported in GEOM
def checkResultInGEOM():
- geomObject_1 = getLastGEOMShape()
+ geomObject_1 = getLastGEOMShape() # the second, translation result
group_1_GEOM = getSubObject(geomObject_1, 1)
assert group_1_GEOM.GetName() == 'faces_top'
- assert geompy.NumberOfFaces(group_1_GEOM) == 3
+ assert geompy.NumberOfFaces(group_1_GEOM) == 1 # 2 faces are in the first result, only one here
# coordinates of the barycenters of the faces of Group_1
- coords_1 = [[-5, 5, 10], [10, 10, 20], [25, 5, 10]]
+ coords_1 = [[25, 5, 10]]
checkGroupByCoords(group_1_GEOM, coords_1)
group_2_GEOM = getSubObject(geomObject_1, 2)
assert group_2_GEOM.GetName() == 'edges_x'
- assert geompy.NumberOfEdges(group_2_GEOM) == 3
+ assert geompy.NumberOfEdges(group_2_GEOM) == 1 # 2 edges are in the first result, only one here
# coordinates of the barycenters of the edges of Group_2
- coords_2 = [[-5, 0, 0], [10, 0, 0], [25, 0, 0]]
+ coords_2 = [[25, 0, 0]]
checkGroupByCoords(group_2_GEOM, coords_2)
group_3_GEOM = getSubObject(geomObject_1, 3)
assert group_3_GEOM.GetName() == 'vertices_bottom'
- assert geompy.NumberOfSubShapes(group_3_GEOM, geompy.ShapeType["VERTEX"]) == 8
+ assert geompy.NumberOfSubShapes(group_3_GEOM, geompy.ShapeType["VERTEX"]) == 3 # 3 of 8
# coordinates of the points of of Group_3
- coords_3 = [[-10, 0, 0], [-10, 10, 0], [0, 10, 0], [0, 20, 0], [20, 20, 0], [20, 10, 0], [30, 10, 0], [30, 0, 0]]
+ coords_3 = [[20, 10, 0], [30, 10, 0], [30, 0, 0]]
checkGroupByCoords(group_3_GEOM, coords_3)
group_4_GEOM = getSubObject(geomObject_1, 4)
assert group_4_GEOM.GetName() == 'solids_small'
- assert geompy.NumberOfSolids(group_4_GEOM) == 2
+ assert geompy.NumberOfSolids(group_4_GEOM) == 1 # 1 of 2
# coordinates of the barycenters of the solids of Group_4
- coords_4 = [[-5, 5, 5], [25, 5, 5]]
+ coords_4 = [[25, 5, 5]]
checkGroupByCoords(group_4_GEOM, coords_4)
field_1_GEOM = getSubObject(geomObject_1, 5)
assert field_1_GEOM.GetName() == 'Field_solids'
- assert field_1_GEOM.GetStep(0).GetValues() == [1.0, 2.0, 3.0]
+ assert field_1_GEOM.GetStep(0).GetValues() == [3.0]
field_2_GEOM = getSubObject(geomObject_1, 6)
assert field_2_GEOM.GetName() == 'Field_faces'
- assert field_2_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0]
+ assert field_2_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0]
field_3_GEOM = getSubObject(geomObject_1, 7)
assert field_3_GEOM.GetName() == 'Field_edges'
- assert field_3_GEOM.GetStep(0).GetValues() == [2.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0]
+ assert field_3_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0]
field_4_GEOM = getSubObject(geomObject_1, 8)
assert field_4_GEOM.GetName() == 'Field_vertices'
- assert field_4_GEOM.GetStep(0).GetValues() == [2.0, 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0]
+ assert field_4_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0]
pass
def getKind(self):
return ExportFeature.ID()
- ## This feature is action: has no property pannel and executes immediately.
+ ## This feature is action: has no property panel and executes immediately.
def isAction(self):
return True
## Export the results, groups and fields via XAO
def exportViaXAO(self):
- tmpXAOFile = getTmpFileName("xao")
- self.tmpXAOFile = tmpXAOFile
- #print "Export to %s"%tmpXAOFile
- exportXAO = ExchangeAPI.exportToXAO(self.Part, tmpXAOFile, "automatic_shaper_export_to_XAO")
- if not os.path.exists(tmpXAOFile) or os.stat(tmpXAOFile).st_size == 0:
- exportXAO.feature().setError("Error in exportToXAO. No XAO file has been created.")
- return
- imported, shape, subShapes, groups, fields = self.geompy.ImportXAO(tmpXAOFile)
- self.geompy.addToStudy( shape, shape.GetName() )
- # add sub-shapes and groups to the object browser
- for obj in subShapes + groups:
- name = obj.GetName()
- self.geompy.addToStudyInFather(shape, obj, name)
- # add fields to the object browser
- for field in fields:
- name = field.GetName()
- self.geompy.addToStudyInFather(shape, field, name)
- # add steps to the object browser
- steps = field.getSteps()
- for i_step in steps:
- step = field.getStep(i_step)
- i_stamp = step.GetStamp()
- step_name = "Step %i %i"%(i_step, i_stamp)
- self.geompy.addToStudyInFather( field, step, step_name )
- # Remove the temporary file
- os.remove(tmpXAOFile)
+ # iterate all results of Part, export one by one due to issue 2882
+ for aResIndex in range(self.Part.size(model.ModelAPI_ResultBody_group())):
+ anObject = self.Part.object(model.ModelAPI_ResultBody_group(), aResIndex)
+ aResult = model.objectToResult(anObject)
+ if not aResult is None:
+ tmpXAOFile = getTmpFileName("xao")
+ self.tmpXAOFile = tmpXAOFile
+ #print "Export to %s"%tmpXAOFile
+ exportXAO = ExchangeAPI.exportToXAO(self.Part, tmpXAOFile, model.selection(aResult), "automatic_shaper_export_to_XAO")
+ if not os.path.exists(tmpXAOFile) or os.stat(tmpXAOFile).st_size == 0:
+ exportXAO.feature().setError("Error in exportToXAO. No XAO file has been created.")
+ return
+ imported, shape, subShapes, groups, fields = self.geompy.ImportXAO(tmpXAOFile)
+ self.geompy.addToStudy( shape, shape.GetName() )
+ # add sub-shapes and groups to the object browser
+ for obj in subShapes + groups:
+ name = obj.GetName()
+ self.geompy.addToStudyInFather(shape, obj, name)
+ # add fields to the object browser
+ for field in fields:
+ name = field.GetName()
+ self.geompy.addToStudyInFather(shape, field, name)
+ # add steps to the object browser
+ steps = field.getSteps()
+ for i_step in steps:
+ step = field.getStep(i_step)
+ i_stamp = step.GetStamp()
+ step_name = "Step %i %i"%(i_step, i_stamp)
+ self.geompy.addToStudyInFather( field, step, step_name )
+ # Remove the temporary file
+ os.remove(tmpXAOFile)
+ pass
pass
## Exports all shapes and groups into the GEOM module.
#include <ModelHighAPI_Tools.h>
#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Services.h>
+#include <ModelHighAPI_Selection.h>
//--------------------------------------------------------------------------------------
ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature)
apply(); // finish operation to make sure the export is done on the current state of the history
}
+ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::string & theFilePath, const ModelHighAPI_Selection& theResult,
+ const std::string & theAuthor, const std::string & theGeometryName)
+ : ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+ fillAttribute("XAO", theFeature->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID()));
+ fillAttribute(theFilePath, theFeature->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID()));
+ fillAttribute(theAuthor, theFeature->string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID()));
+ fillAttribute(theGeometryName,
+ theFeature->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID()));
+ fillAttribute("XAO", theFeature->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID()));
+ std::list<ModelHighAPI_Selection> aListOfOneSel;
+ aListOfOneSel.push_back(theResult);
+ fillAttribute(aListOfOneSel,
+ theFeature->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()));
+ execute();
+ apply(); // finish operation to make sure the export is done on the current state of the history
+}
+
+
/// Constructor with values for export in other formats than XAO.
ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::string & theFilePath,
return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theAuthor, theGeometryName));
}
+ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape,
+ const std::string & theAuthor, const std::string & theGeometryName)
+{
+ apply(); // finish previous operation to make sure all previous operations are done
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ thePart->addFeature(ExchangePlugin_ExportFeature::ID());
+ // special internal case when for XAO a selection list is filled
+ return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theSelectedShape, "XAO"));
+}
+
//--------------------------------------------------------------------------------------
const std::string & theAuthor = std::string(),
const std::string & theGeometryName = std::string());
+ /// Constructor with values for XAO of selected result export.
+ EXCHANGEAPI_EXPORT
+ explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::string & theFilePath,
+ const ModelHighAPI_Selection& theResult,
+ const std::string & theAuthor,
+ const std::string & theGeometryName = std::string());
+
/// Constructor with values for export in other formats than XAO.
EXCHANGEAPI_EXPORT
explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::string & theFileFormat = std::string());
/**\ingroup CPPHighAPI
- * \brief Export XAO
+ * \brief Exports to XAO file all results of the current document
*/
EXCHANGEAPI_EXPORT
ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
const std::string & theAuthor = std::string(),
const std::string & theGeometryName = std::string());
+/**\ingroup CPPHighAPI
+* \brief Exports to XAO file the selected result with groups parts related to it only.
+*/
+EXCHANGEAPI_EXPORT
+ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath,
+ const ModelHighAPI_Selection& theSelectedShape,
+ const std::string & theAuthor = std::string(),
+ const std::string & theGeometryName = std::string());
+
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
#endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_EXPORT_H_ */
#include <ModelAPI_ResultField.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_Tools.h>
#include <Events_InfoMessage.h>
return aStr.str();
}
+/// Returns true if something in selection is presented in the results list
+static bool isInResults(AttributeSelectionListPtr theSelection,
+ const std::list<ResultBodyPtr>& theResults,
+ std::set<ResultBodyPtr>& theCashedResults)
+{
+ // collect all results into a cashed set
+ if (theCashedResults.empty()) {
+ std::list<ResultPtr> aResults;
+ std::list<ResultBodyPtr>::const_iterator aRes = theResults.cbegin();
+ for(; aRes != theResults.cend(); aRes++) {
+ if (theCashedResults.count(*aRes))
+ continue;
+ else
+ theCashedResults.insert(*aRes);
+ std::list<ResultPtr> aResults;
+ ModelAPI_Tools::allSubs(*aRes, aResults, false);
+ for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
+ theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
+ }
+ }
+ }
+ // if context is in results, return true
+ for(int a = 0; a < theSelection->size(); a++) {
+ AttributeSelectionPtr anAttr = theSelection->value(a);
+ ResultBodyPtr aSelected= std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
+ if (aSelected.get() && theCashedResults.count(aSelected))
+ return true;
+ }
+ return false;
+}
+
void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
{
try {
// make shape for export from all results
std::list<GeomShapePtr> aShapes;
std::list<ResultBodyPtr> aResults;
- int aBodyCount = document()->size(ModelAPI_ResultBody::group());
- for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
- ResultBodyPtr aResultBody =
- std::dynamic_pointer_cast<ModelAPI_ResultBody>(
- document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
- if (!aResultBody.get())
- continue;
- aShapes.push_back(aResultBody->shape());
- aResults.push_back(aResultBody);
+
+ AttributeSelectionListPtr aSelection = selectionList(SELECTION_LIST_ID());
+ bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
+ if (aIsSelection) { // a mode for export to geom result by result
+ for(int a = 0; a < aSelection->size(); a++) {
+ AttributeSelectionPtr anAttr = aSelection->value(a);
+ ResultBodyPtr aBodyContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
+ if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
+ aResults.push_back(aBodyContext);
+ GeomShapePtr aShape = anAttr->value();
+ if (!aShape.get())
+ aShape = aBodyContext->shape();
+ aShapes.push_back(aShape);
+ }
+ }
+ } else {
+ int aBodyCount = document()->size(ModelAPI_ResultBody::group());
+ for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
+ ResultBodyPtr aResultBody =
+ std::dynamic_pointer_cast<ModelAPI_ResultBody>(
+ document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
+ if (!aResultBody.get())
+ continue;
+ aShapes.push_back(aResultBody->shape());
+ aResults.push_back(aResultBody);
+ }
+ }
+ if (aShapes.empty()) {
+ setError("No shapes to export");
+ return;
}
+
+
GeomShapePtr aShape = (aShapes.size() == 1)
? *aShapes.begin()
: GeomAlgoAPI_CompoundBuilder::compound(aShapes);
// geometry name
std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
- if (aGeometryName.empty() && aBodyCount == 1) {
+ if (aGeometryName.empty() && aResults.size() == 1) {
// get the name from the first result
ResultBodyPtr aResultBody = *aResults.begin();
aGeometryName = aResultBody->data()->name();
aXao.getGeometry()->setName(aGeometryName);
+ std::set<ResultBodyPtr> allResultsCashed; // cash to speed up searching in all results selected
+
// groups
int aGroupCount = document()->size(ModelAPI_ResultGroup::group());
for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
AttributeSelectionListPtr aSelectionList =
aGroupFeature->selectionList("group_list");
+ if (!isInResults(aSelectionList, aResults, allResultsCashed))// skip group not used in results
+ continue;
+
// conversion of dimension
std::string aSelectionType = aSelectionList->selectionType();
std::string aDimensionString =
int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSelection->value());
+ if (aReferenceID == 0) // selected value does not found in the exported shape
+ continue;
+
std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
int anElementID =
aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
AttributeSelectionListPtr aSelectionList =
aFieldFeature->selectionList("selected");
+ std::string aSelectionType = aSelectionList->selectionType();
+ bool isWholePart = aSelectionType == "part";
+
+ if (!isWholePart &&
+ !isInResults(aSelectionList, aResults, allResultsCashed))// skip field not used in results
+ continue;
// conversion of dimension
- std::string aSelectionType = aSelectionList->selectionType();
std::string aDimensionString =
ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
- bool isWholePart = aSelectionType == "part";
// get tables and their type
std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
if (!isWholePart) {
// element index actually is the ID of the selection
AttributeSelectionPtr aSelection = aSelectionList->value(aRow - 1);
-
- // complex conversion of reference id to element index
- // gives bad id in case the selection is done from python script
- // => using GeomAlgoAPI_CompoundBuilder::id instead
- //int aReferenceID_old = aSelection->Id();
-
int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSelection->value());
+ if (aReferenceID == 0) // selected value does not found in the exported shape
+ continue;
std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
anElementID =
return mySubs.at(theIndex);
}
-bool Model_ResultBody::isSub(ObjectPtr theObject, int& theIndex) const
+bool Model_ResultBody::isSub(ObjectPtr theResult, int& theIndex) const
{
- std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theObject);
+ std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theResult);
if (aFound != mySubsMap.end()) {
theIndex = aFound->second;
return true;
MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_ResultBody> subResult(
const int theIndex, bool forTree = false) const = 0;
- /// Returns true if feature or result belong to this composite feature as subs
+ /// Returns true if theResult belong to this composite result as sub.
/// Returns theIndex - zero based index of sub if found
- MODELAPI_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const = 0;
+ MODELAPI_EXPORT virtual bool isSub(ObjectPtr theResult, int& theIndex) const = 0;
/// \brief Stores the shape (called by the execution method).
/// param[in] theShape shape to store.