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})
+
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());
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) {
--- /dev/null
+/data/spo/Shaper/sources/src/XAO/tests/data/Box_1.brep
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<XAO version="1.0" author="me">
+ <geometry name="mygeom">
+ <shape format="BREP"><![CDATA[
+CASCADE Topology V1, (c) Matra-Datavision
+Locations 0
+Curve2ds 24
+1 0 0 1 0
+1 0 0 1 0
+1 200 0 0 -1
+1 0 0 0 1
+1 0 -200 1 0
+1 0 0 1 0
+1 0 0 0 -1
+1 0 0 0 1
+1 0 0 1 0
+1 0 200 1 0
+1 200 0 0 -1
+1 200 0 0 1
+1 0 -200 1 0
+1 0 200 1 0
+1 0 0 0 -1
+1 200 0 0 1
+1 0 0 0 1
+1 0 0 1 0
+1 200 0 0 1
+1 0 0 1 0
+1 0 0 0 1
+1 0 200 1 0
+1 200 0 0 1
+1 0 200 1 0
+Curves 12
+1 0 0 0 0 0 1
+1 0 0 200 -0 1 0
+1 0 200 0 0 0 1
+1 0 0 0 -0 1 0
+1 200 0 0 0 0 1
+1 200 0 200 0 1 0
+1 200 200 0 0 0 1
+1 200 0 0 -0 1 0
+1 0 0 0 1 0 -0
+1 0 0 200 1 0 -0
+1 0 200 0 1 0 -0
+1 0 200 200 1 0 -0
+Polygon3D 0
+PolygonOnTriangulations 24
+2 1 2
+p 0.8000000008 1 0 200
+2 1 4
+p 0.8000000008 1 0 200
+2 2 3
+p 0.8000000008 1 0 200
+2 1 2
+p 0.8000000008 1 0 200
+2 4 3
+p 0.8000000008 1 0 200
+2 1 4
+p 0.8000000008 1 0 200
+2 1 4
+p 0.8000000008 1 0 200
+2 1 2
+p 0.8000000008 1 0 200
+2 1 2
+p 0.8000000008 1 0 200
+2 2 3
+p 0.8000000008 1 0 200
+2 2 3
+p 0.8000000008 1 0 200
+2 4 3
+p 0.8000000008 1 0 200
+2 4 3
+p 0.8000000008 1 0 200
+2 2 3
+p 0.8000000008 1 0 200
+2 1 4
+p 0.8000000008 1 0 200
+2 4 3
+p 0.8000000008 1 0 200
+2 1 2
+p 0.8000000008 1 0 200
+2 1 4
+p 0.8000000008 1 0 200
+2 4 3
+p 0.8000000008 1 0 200
+2 1 4
+p 0.8000000008 1 0 200
+2 1 2
+p 0.8000000008 1 0 200
+2 2 3
+p 0.8000000008 1 0 200
+2 4 3
+p 0.8000000008 1 0 200
+2 2 3
+p 0.8000000008 1 0 200
+Surfaces 6
+1 0 0 0 1 0 -0 0 0 1 0 -1 0
+1 0 0 0 -0 1 0 0 0 1 1 0 -0
+1 0 0 200 0 0 1 1 0 -0 -0 1 0
+1 0 200 0 -0 1 0 0 0 1 1 0 -0
+1 0 0 0 0 0 1 1 0 -0 -0 1 0
+1 200 0 0 1 0 -0 0 0 1 0 -1 0
+Triangulations 6
+4 2 1 0
+0 0 0 0 0 200 0 200 200 0 200 0 0 0 200 0 200 -200 0 -200 2 4 3 2 1 4
+4 2 1 0
+0 0 0 200 0 0 200 0 200 0 0 200 0 0 0 200 200 200 200 0 3 2 1 3 1 4
+4 2 1 0
+0 0 200 0 200 200 200 200 200 200 0 200 0 0 0 200 200 200 200 0 3 2 1 3 1 4
+4 2 1 0
+0 200 0 200 200 0 200 200 200 0 200 200 0 0 0 200 200 200 200 0 3 2 1 3 1 4
+4 2 1 0
+0 0 0 0 200 0 200 200 0 200 0 0 0 0 0 200 200 200 200 0 3 2 1 3 1 4
+4 2 1 0
+200 0 0 200 0 200 200 200 200 200 200 0 0 0 200 0 200 -200 0 -200 2 4 3 2 1 4
+
+TShapes 34
+Ve
+1e-07
+0 0 200
+0 0
+
+0101101
+*
+Ve
+1e-07
+0 0 0
+0 0
+
+0101101
+*
+Ed
+ 1e-07 1 1 0
+1 1 0 0 200
+2 1 1 0 0 200
+2 2 2 0 0 200
+6 1 1 0
+6 2 2 0
+0
+
+0101000
+-34 0 +33 0 *
+Ve
+1e-07
+0 200 200
+0 0
+
+0101101
+*
+Ed
+ 1e-07 1 1 0
+1 2 0 0 200
+2 3 1 0 0 200
+2 4 3 0 0 200
+6 3 1 0
+6 4 3 0
+0
+
+0101000
+-31 0 +34 0 *
+Ve
+1e-07
+0 200 0
+0 0
+
+0101101
+*
+Ed
+ 1e-07 1 1 0
+1 3 0 0 200
+2 5 1 0 0 200
+2 6 4 0 0 200
+6 5 1 0
+6 6 4 0
+0
+
+0101000
+-31 0 +29 0 *
+Ed
+ 1e-07 1 1 0
+1 4 0 0 200
+2 7 1 0 0 200
+2 8 5 0 0 200
+6 7 1 0
+6 8 5 0
+0
+
+0101000
+-29 0 +33 0 *
+Wi
+
+0101000
+-32 0 -30 0 +28 0 +27 0 *
+Fa
+0 1e-07 1 0
+2 1
+0111000
++26 0 *
+Ve
+1e-07
+200 0 200
+0 0
+
+0101101
+*
+Ve
+1e-07
+200 0 0
+0 0
+
+0101101
+*
+Ed
+ 1e-07 1 1 0
+1 5 0 0 200
+2 9 6 0 0 200
+2 10 2 0 0 200
+6 9 6 0
+6 10 2 0
+0
+
+0101000
+-24 0 +23 0 *
+Ve
+1e-07
+200 200 200
+0 0
+
+0101101
+*
+Ed
+ 1e-07 1 1 0
+1 6 0 0 200
+2 11 6 0 0 200
+2 12 3 0 0 200
+6 11 6 0
+6 12 3 0
+0
+
+0101000
+-21 0 +24 0 *
+Ve
+1e-07
+200 200 0
+0 0
+
+0101101
+*
+Ed
+ 1e-07 1 1 0
+1 7 0 0 200
+2 13 6 0 0 200
+2 14 4 0 0 200
+6 13 6 0
+6 14 4 0
+0
+
+0101000
+-21 0 +19 0 *
+Ed
+ 1e-07 1 1 0
+1 8 0 0 200
+2 15 6 0 0 200
+2 16 5 0 0 200
+6 15 6 0
+6 16 5 0
+0
+
+0101000
+-19 0 +23 0 *
+Wi
+
+0101000
+-22 0 -20 0 +18 0 +17 0 *
+Fa
+0 1e-07 6 0
+2 6
+0111000
++16 0 *
+Ed
+ 1e-07 1 1 0
+1 9 0 0 200
+2 17 2 0 0 200
+2 18 5 0 0 200
+6 17 2 0
+6 18 5 0
+0
+
+0101000
+-23 0 +33 0 *
+Ed
+ 1e-07 1 1 0
+1 10 0 0 200
+2 19 2 0 0 200
+2 20 3 0 0 200
+6 19 2 0
+6 20 3 0
+0
+
+0101000
+-24 0 +34 0 *
+Wi
+
+0101000
+-14 0 -22 0 +13 0 +32 0 *
+Fa
+0 1e-07 2 0
+2 2
+0111000
++12 0 *
+Ed
+ 1e-07 1 1 0
+1 11 0 0 200
+2 21 4 0 0 200
+2 22 5 0 0 200
+6 21 4 0
+6 22 5 0
+0
+
+0101000
+-19 0 +29 0 *
+Ed
+ 1e-07 1 1 0
+1 12 0 0 200
+2 23 4 0 0 200
+2 24 3 0 0 200
+6 23 4 0
+6 24 3 0
+0
+
+0101000
+-21 0 +31 0 *
+Wi
+
+0101000
+-10 0 -18 0 +9 0 +28 0 *
+Fa
+0 1e-07 4 0
+2 4
+0111000
++8 0 *
+Wi
+
+0101000
+-27 0 -10 0 +17 0 +14 0 *
+Fa
+0 1e-07 5 0
+2 5
+0111000
++6 0 *
+Wi
+
+0101000
+-30 0 -9 0 +20 0 +13 0 *
+Fa
+0 1e-07 3 0
+2 3
+0111000
++4 0 *
+Sh
+
+0101100
+-25 0 +15 0 -11 0 +7 0 -5 0 +3 0 *
+So
+
+1100000
++2 0 *
+
++1 0 ]]></shape>
+ <topology>
+ <vertices count="8">
+ <vertex index="0" name="" reference="6"/>
+ <vertex index="1" name="" reference="7"/>
+ <vertex index="2" name="" reference="9"/>
+ <vertex index="3" name="" reference="11"/>
+ <vertex index="4" name="" reference="16"/>
+ <vertex index="5" name="" reference="17"/>
+ <vertex index="6" name="" reference="19"/>
+ <vertex index="7" name="" reference="21"/>
+ </vertices>
+ <edges count="12">
+ <edge index="0" name="" reference="5"/>
+ <edge index="1" name="" reference="8"/>
+ <edge index="2" name="" reference="10"/>
+ <edge index="3" name="" reference="12"/>
+ <edge index="4" name="" reference="15"/>
+ <edge index="5" name="" reference="18"/>
+ <edge index="6" name="" reference="20"/>
+ <edge index="7" name="" reference="22"/>
+ <edge index="8" name="" reference="25"/>
+ <edge index="9" name="" reference="26"/>
+ <edge index="10" name="" reference="29"/>
+ <edge index="11" name="" reference="30"/>
+ </edges>
+ <faces count="6">
+ <face index="0" name="" reference="3"/>
+ <face index="1" name="" reference="13"/>
+ <face index="2" name="" reference="23"/>
+ <face index="3" name="" reference="27"/>
+ <face index="4" name="" reference="31"/>
+ <face index="5" name="" reference="33"/>
+ </faces>
+ <solids count="1">
+ <solid index="0" name="" reference="1"/>
+ </solids>
+ </topology>
+ </geometry>
+ <groups count="2">
+ <group name="boite_1" dimension="solid" count="1">
+ <element index="0"/>
+ </group>
+ <group name="" dimension="face" count="2">
+ <element index="0"/>
+ <element index="1"/>
+ </group>
+ </groups>
+ <fields count="0"/>
+</XAO>
# 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
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
#=========================================================================
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
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
#=========================================================================