From: spo Date: Wed, 22 Jun 2016 09:19:32 +0000 (+0300) Subject: Add XAO tests X-Git-Tag: V_2.4.0~53 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=da08ab63a0b7be551ef70d25ac11e0bd3bcbcf96;p=modules%2Fshaper.git Add XAO tests --- diff --git a/src/ExchangePlugin/CMakeLists.txt b/src/ExchangePlugin/CMakeLists.txt index 53a8974fb..b1c58c676 100644 --- a/src/ExchangePlugin/CMakeLists.txt +++ b/src/ExchangePlugin/CMakeLists.txt @@ -59,9 +59,22 @@ INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) ADD_UNIT_TESTS(TestImport.py TestExport.py) -CONFIGURE_FILE(Test/Data/solid.brep Data/solid.brep COPYONLY) -CONFIGURE_FILE(Test/Data/solid.brp Data/solid.brp COPYONLY) -CONFIGURE_FILE(Test/Data/screw.step Data/screw.step COPYONLY) -CONFIGURE_FILE(Test/Data/screw.stp Data/screw.stp COPYONLY) -CONFIGURE_FILE(Test/Data/bearing.iges Data/bearing.iges COPYONLY) -CONFIGURE_FILE(Test/Data/bearing.igs Data/bearing.igs COPYONLY) +SET(DATA_FILES + solid.brep + solid.brp + screw.step + screw.stp + bearing.iges + bearing.igs + Box_1.brep + test.xao + export_ref.xao +) + +FOREACH(file ${DATA_FILES}) + CONFIGURE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/Test/Data/${file} + ${CMAKE_CURRENT_BINARY_DIR}/Data/${file} + COPYONLY) +ENDFOREACH(file ${DATA_FIELS}) + diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index bdbbce4b4..4060c3e04 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -53,7 +53,8 @@ ExchangePlugin_ImportFeature::~ExchangePlugin_ImportFeature() void ExchangePlugin_ImportFeature::initAttributes() { data()->addAttribute(ExchangePlugin_ImportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(ExchangePlugin_ImportFeature::FEATURES_ID(), ModelAPI_AttributeRefList::typeId()); + AttributePtr aFeaturesAttribute = data()->addAttribute(ExchangePlugin_ImportFeature::FEATURES_ID(), ModelAPI_AttributeRefList::typeId()); + aFeaturesAttribute->setIsArgument(false); ModelAPI_Session::get()->validators()->registerNotObligatory( getKind(), ExchangePlugin_ImportFeature::FEATURES_ID()); @@ -185,13 +186,6 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName) aSelectionList->value(anElementIndex)->setId(aReferenceID); } -// -// aRefListOfGroups->append(aGroupFeature); -// -// // hide the group in the history -// document()->setCurrentFeature(aGroupFeature, false); -// // groups features is internal part of the import -// aGroupFeature->setInHistory(aGroupFeature, false); } } catch (XAO::XAO_Exception& e) { diff --git a/src/ExchangePlugin/Test/Data/Box_1.brep b/src/ExchangePlugin/Test/Data/Box_1.brep new file mode 120000 index 000000000..67a06ebf0 --- /dev/null +++ b/src/ExchangePlugin/Test/Data/Box_1.brep @@ -0,0 +1 @@ +/data/spo/Shaper/sources/src/XAO/tests/data/Box_1.brep \ No newline at end of file diff --git a/src/ExchangePlugin/Test/Data/export_ref.xao b/src/ExchangePlugin/Test/Data/export_ref.xao new file mode 100644 index 000000000..0848d6714 --- /dev/null +++ b/src/ExchangePlugin/Test/Data/export_ref.xao @@ -0,0 +1,417 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ExchangePlugin/Test/TestExport.py b/src/ExchangePlugin/Test/TestExport.py index 50b8fc883..f295039ce 100644 --- a/src/ExchangePlugin/Test/TestExport.py +++ b/src/ExchangePlugin/Test/TestExport.py @@ -74,6 +74,54 @@ def testExport(theType, theFormat, theFile, theVolume, theDelta): # Test exported file by importing testImport(theType, theFile, theVolume, theDelta) +def testExportXAO(): + # Import a reference part + aSession.startOperation("Add part") + aPartFeature = aSession.moduleDocument().addFeature("Part") + aSession.finishOperation() + aPart = aSession.activeDocument() + + aSession.startOperation("Import Box_1") + anImportFeature = aPart.addFeature("Import") + anImportFeature.string("file_path").setValue("Data/Box_1.brep") + anImportFeature.execute() + aSession.finishOperation() + + # Create groups + aSession.startOperation() + aGroupFeature = aSession.activeDocument().addFeature("Group") + aGroupFeature.data().setName("boite_1") + aSelectionListAttr = aGroupFeature.selectionList("group_list") + aSelectionListAttr.setSelectionType("Solids") + aSelectionListAttr.append(anImportFeature.lastResult(), None) + aGroupFeature.execute() + aSession.finishOperation() + + aSession.startOperation() + aGroupFeature = aSession.activeDocument().addFeature("Group") + aGroupFeature.data().setName("") + aSelectionListAttr = aGroupFeature.selectionList("group_list") + aSelectionListAttr.setSelectionType("Faces") + aSelectionListAttr.append("Box_1_1/Shape1_1", "face") + aSelectionListAttr.append("Box_1_1/Shape2_1", "face") + aGroupFeature.execute() + aSession.finishOperation() + + # Export + aSession.startOperation("Export") + anExportFeature = aPart.addFeature("Export") + anExportFeature.string("ExportType").setValue("XAO") + anExportFeature.string("file_path").setValue("Data/export.xao") + anExportFeature.string("file_format").setValue("XAO") + anExportFeature.string("xao_author").setValue("me") + anExportFeature.string("xao_geometry_name").setValue("mygeom") + anExportFeature.execute() + aSession.finishOperation() + + # Check exported file + import filecmp + assert filecmp.cmp("Data/export.xao", "Data/export_ref.xao") + if __name__ == '__main__': #========================================================================= # Export a shape into BREP @@ -94,5 +142,9 @@ if __name__ == '__main__': testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17) testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17) #========================================================================= +# Export a shape into XAO +#========================================================================= + testExportXAO() +#========================================================================= # End of test #========================================================================= diff --git a/src/ExchangePlugin/Test/TestImport.py b/src/ExchangePlugin/Test/TestImport.py index 624f7f318..de752ffb1 100644 --- a/src/ExchangePlugin/Test/TestImport.py +++ b/src/ExchangePlugin/Test/TestImport.py @@ -49,6 +49,47 @@ def testImport(theType, theFile, theVolume, theDelta): aResVolume = GeomAlgoAPI_ShapeTools.volume(aShape) assert (math.fabs(aResVolume - aRefVolume) < theDelta), "{0}: The volume is wrong: expected = {1}, real = {2}".format(theType, aRefVolume, aResVolume) +def testImportXAO(): + # Create a part for import + aSession.startOperation("Create part for import") + aPartFeature = aSession.moduleDocument().addFeature("Part") + aSession.finishOperation() + aPart = aSession.activeDocument() + + aSession.startOperation("Import XAO") + anImportFeature = aPart.addFeature("Import") + anImportFeature.string("file_path").setValue("Data/test.xao") + anImportFeature.execute() + aSession.finishOperation() + + # Check results + assert anImportFeature.error() == '' + assert anImportFeature.name() == "mygeom" + assert len(anImportFeature.results()) == 1 + assert modelAPI_ResultBody(anImportFeature.firstResult()) + assert anImportFeature.firstResult().data().name() == "mygeom_1" + aCompositeFeature = featureToCompositeFeature(anImportFeature) + assert aCompositeFeature.numberOfSubs(False) == 2 + + aFeature1 = aCompositeFeature.subFeature(0, False) + assert aFeature1.getKind() == "Group" + assert aFeature1.name() == "boite_1" + + aSelectionList = aFeature1.selectionList("group_list") + assert aSelectionList.selectionType() == "Solids" + assert aSelectionList.size() == 1 + assert aSelectionList.value(0).namingName("") == "mygeom_1_1" + + aFeature2 = aCompositeFeature.subFeature(1, False) + assert aFeature2.getKind() == "Group" + assert aFeature2.name() == "Group_2" + + aSelectionList = aFeature2.selectionList("group_list") + assert aSelectionList.selectionType() == "Faces" + assert aSelectionList.size() == 2 + assert aSelectionList.value(0).namingName("") == "mygeom_1/Shape1_1" + assert aSelectionList.value(1).namingName("") == "mygeom_1/Shape2_1" + if __name__ == '__main__': #========================================================================= # Create a shape imported from BREP @@ -66,5 +107,9 @@ if __name__ == '__main__': testImport("IGES", "Data/bearing.iges", 6.86970803067e-14, 10 ** -25) testImport("IGS", "Data/bearing.igs", 6.86970803067e-14, 10 ** -25) #========================================================================= +# Create a shape imported from XAO +#========================================================================= + testImportXAO() +#========================================================================= # End of test #=========================================================================