]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for test cases.
authordbv <dbv@opencascade.com>
Mon, 23 May 2016 08:27:04 +0000 (11:27 +0300)
committerdbv <dbv@opencascade.com>
Mon, 23 May 2016 08:27:25 +0000 (11:27 +0300)
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/Test/TestPartition.py
src/FeaturesPlugin/partition_widget.xml
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h

index 4f9d860c7a9fb0e75ffde155e2fc122a4fc11cd8..b451667acad83e8d703d5be7c7433596a1fcfc6a 100644 (file)
@@ -444,16 +444,31 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
                                                          const std::list<std::string>& theArguments,
                                                          std::string& theError) const
 {
-  GeomValidators_BodyShapes aBodyValidator;
-  if(aBodyValidator.isValid(theAttribute, theArguments, theError)) {
-    return true;
-  }
+  std::string anAttributeType = theAttribute->attributeType();
+  if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr aSelectionListAttr =
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
 
-  GeomValidators_FeatureKind aFeatureKindValidator;
-  if(aFeatureKindValidator.isValid(theAttribute, theArguments, theError)) {
-    return true;
+    for(int anIndex = 0; anIndex < aSelectionListAttr->size(); ++anIndex) {
+      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(anIndex);
+
+      GeomValidators_BodyShapes aBodyValidator;
+      if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
+        continue;
+      }
+
+      GeomValidators_FeatureKind aFeatureKindValidator;
+      if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
+        continue;
+      }
+
+      theError = "Only body shapes and construction planes are allowed for selection.";
+      return false;
+    }
+  } else {
+    theError = "This validator supports only " + ModelAPI_AttributeSelectionList::typeId() + " attribute type.";
+    return false;
   }
 
-  theError = "Only body shapes and construction planes are allowed for selection.";
-  return false;
+  return true;
 }
index e126412573a776ff2e6eef8e315a81614aac90d0..c90a2908273493936bc583d413e9d860403a5614 100644 (file)
@@ -94,9 +94,8 @@ aPlaneResult = aPlaneFeature.firstResult()
 aSession.startOperation()
 aPartitionFt = aPart.addFeature("Partition")
 assert (aPartitionFt.getKind() == "Partition")
-aPartitionFt.selectionList("main_objects").append(anExtrusionResult, anExtrusionResult.shape())
-aPartitionFt.selectionList("tool_objects").append(aPlaneResult, None)
-aPartitionFt.boolean("partition_combine").setValue(True)
+aPartitionFt.selectionList("base_objects").append(anExtrusionResult, anExtrusionResult.shape())
+aPartitionFt.selectionList("base_objects").append(aPlaneResult, None)
 aPartitionFt.execute()
 aSession.finishOperation()
 
@@ -116,9 +115,8 @@ aSession.undo()
 aSession.startOperation()
 aPartitionFt = aPart.addFeature("Partition")
 assert (aPartitionFt.getKind() == "Partition")
-aPartitionFt.selectionList("main_objects").append(anExtrusionResult, anExtrusionResult.shape())
-aPartitionFt.selectionList("tool_objects").append(aPlaneResult, None)
-aPartitionFt.boolean("partition_combine").setValue(False)
+aPartitionFt.selectionList("base_objects").append(anExtrusionResult, anExtrusionResult.shape())
+aPartitionFt.selectionList("base_objects").append(aPlaneResult, None)
 aPartitionFt.execute()
 aSession.finishOperation()
 
index ec2ea7105f8ddf9022daf1140495e0df99aa9d8c..593b19864311b7cea196634a60867dd6336c8c41 100755 (executable)
@@ -6,7 +6,6 @@
     tooltip="Select objects for partitioning."
     type_choice="objects"
     concealment="true">
-    <validator id="FeaturesPlugin_ValidatorPartitionSelection"/>
+    <validator id="FeaturesPlugin_ValidatorPartitionSelection" parameters="Plane"/>
   </multi_selector>
-  <!--<validator id="GeomValidators_PartitionArguments" parameters="main_objects,tool_objects,partition_combine"/>-->
 </source>
index e6a89baa122854fa3a6a81d8ef1cb740f91e4680..7f407d6778f19bb900b07e0cd1222a32484f48bf 100644 (file)
@@ -49,9 +49,8 @@
 #include <TopoDS.hxx>
 #include <TopExp_Explorer.hxx>
 
-namespace GeomAlgoAPI_ShapeTools {
 //==================================================================================================
-double volume(const std::shared_ptr<GeomAPI_Shape> theShape)
+double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
 {
   GProp_GProps aGProps;
   if(!theShape.get()) {
@@ -67,7 +66,7 @@ double volume(const std::shared_ptr<GeomAPI_Shape> theShape)
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape)
+std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeTools::centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape)
 {
   GProp_GProps aGProps;
   if(!theShape) {
@@ -91,10 +90,10 @@ std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> t
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Shape> combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
-                                             const GeomAPI_Shape::ShapeType theType,
-                                             ListOfShape& theCombinedShapes,
-                                             ListOfShape& theFreeShapes)
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
+                                                                     const GeomAPI_Shape::ShapeType theType,
+                                                                     ListOfShape& theCombinedShapes,
+                                                                     ListOfShape& theFreeShapes)
 {
   GeomShapePtr aResult = theCompound;
 
@@ -270,7 +269,7 @@ static TopoDS_Compound makeCompound(const NCollection_List<TopoDS_Shape> theShap
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Shape> groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound)
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound)
 {
   GeomShapePtr aResult = theCompound;
 
@@ -338,7 +337,7 @@ std::shared_ptr<GeomAPI_Shape> groupSharedTopology(const std::shared_ptr<GeomAPI
 }
 
 //==================================================================================================
-std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge)
+std::list<std::shared_ptr<GeomAPI_Pnt> > GeomAlgoAPI_ShapeTools::getBoundingBox(const ListOfShape& theShapes, const double theEnlarge)
 {
   // Bounding box of all objects.
   Bnd_Box aBndBox;
@@ -372,7 +371,7 @@ std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theSh
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace)
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace)
 {
   if (!theFace.get())
     return std::shared_ptr<GeomAPI_Shape>();
@@ -394,8 +393,8 @@ std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Shape> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
-                                              const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints)
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
+                                                                     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints)
 {
   std::shared_ptr<GeomAPI_Shape> aResultShape;
 
@@ -447,9 +446,9 @@ std::shared_ptr<GeomAPI_Shape> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape
 }
 
 //==================================================================================================
-void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
-                std::shared_ptr<GeomAPI_Vertex>& theV1,
-                std::shared_ptr<GeomAPI_Vertex>& theV2)
+void GeomAlgoAPI_ShapeTools::findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
+                                        std::shared_ptr<GeomAPI_Vertex>& theV1,
+                                        std::shared_ptr<GeomAPI_Vertex>& theV2)
 {
   if(!theShape.get()) {
     std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex);
@@ -471,10 +470,10 @@ void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
 }
 
 //==================================================================================================
-void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
-                        const std::shared_ptr<GeomAPI_Dir> theDirection,
-                        const ListOfShape& theWires,
-                        ListOfShape& theFaces)
+void GeomAlgoAPI_ShapeTools::makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
+                                                const std::shared_ptr<GeomAPI_Dir> theDirection,
+                                                const ListOfShape& theWires,
+                                                ListOfShape& theFaces)
 {
   BRepBuilderAPI_MakeFace aMKFace(gp_Pln(theOrigin->impl<gp_Pnt>(),
                                           theDirection->impl<gp_Dir>()));
@@ -503,7 +502,7 @@ void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes)
+std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_ShapeTools::findPlane(const ListOfShape& theShapes)
 {
   TopoDS_Compound aCompound;
   BRep_Builder aBuilder;
@@ -531,8 +530,8 @@ std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes)
 }
 
 //==================================================================================================
-bool isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
-                            const std::shared_ptr<GeomAPI_Shape> theBaseShape)
+bool GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
+                                                   const std::shared_ptr<GeomAPI_Shape> theBaseShape)
 {
   if(!theSubShape.get() || !theBaseShape.get()) {
     return false;
@@ -600,4 +599,3 @@ bool isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
 
   return true;
 }
-} //namespace GeomAlgoAPI_ShapeTools
index 41cc56983bc9a6f779d0c340ba7cac8a5e5ae6bf..3d62588f7360ec40e5719e5109c761fba4226f96 100644 (file)
@@ -17,48 +17,49 @@ class GeomAPI_PlanarEdges;
 class GeomAPI_Pln;
 class GeomAPI_Pnt;
 
-/// \namespace GeomAlgoAPI_ShapeTools
+/// \class GeomAlgoAPI_ShapeTools
 /// \ingroup DataAlgo
 /// \brief Useful tools for working with shapes.
-namespace GeomAlgoAPI_ShapeTools
+class GeomAlgoAPI_ShapeTools
 {
+public:
   /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
-  GEOMALGOAPI_EXPORT double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
+  GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
 
   /// \return the centre of mass of the current face. The coordinates returned for the center of mass
   /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
-  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
+  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
 
   /// \brief Combines faces with common edges to shells, or solids to compsolids.
   /// \param[in] theCompound compound of shapes.
   /// \param[in] theType type of combine.
   /// \param[out] theCombinedShapes resulting shapes.
   /// \param[out] theFreeShapes shapes that does not have common subshapes.
-  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
-                                                                  const GeomAPI_Shape::ShapeType theType,
-                                                                  ListOfShape& theCombinedShapes,
-                                                                  ListOfShape& theFreeShapes);
+  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
+                                                                         const GeomAPI_Shape::ShapeType theType,
+                                                                         ListOfShape& theCombinedShapes,
+                                                                         ListOfShape& theFreeShapes);
 
   /// \brief Groups shapes with shared topology to compounds.
   /// \param[in] theCompound compound of shapes.
   /// \return compound of compounds with shared topology.
-  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
+  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
 
   /// \brief Calculates bounding box for theShapes
   /// \return list of eight points.
   /// \param[in] theShapes list of shapes.
   /// \param[in] theEnlarge enlarges bounding box size.
-  GEOMALGOAPI_EXPORT std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0);
+  GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0);
 
   /// \return infinite plane received from theFace plane.
-  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
+  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
 
   /// \brief Enlarges or reduces plane to fit bounding box.
   /// \return plane that fits to bounding box.
   /// \param[in] thePlane base plane.
   /// \param[in] thePoints bounding box points (shoud be eight).
-  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
-                                                                  const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
+  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
+                                                                         const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
 
   /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
   /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
@@ -66,29 +67,29 @@ namespace GeomAlgoAPI_ShapeTools
   /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
   /// contains no edges theV1 and theV2 are nullified.\n
   /// If none of the above theV1 and theV2 are nullified.
-  GEOMALGOAPI_EXPORT void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
-                                     std::shared_ptr<GeomAPI_Vertex>& theV1,
-                                     std::shared_ptr<GeomAPI_Vertex>& theV2);
+  GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
+                                            std::shared_ptr<GeomAPI_Vertex>& theV1,
+                                            std::shared_ptr<GeomAPI_Vertex>& theV2);
 
   /// \brief Creates faces with holes from wires.
   /// \param[in] theWires base wires.
   /// \param[out] theFaces resulting faces.
-  GEOMALGOAPI_EXPORT void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
-                                             const std::shared_ptr<GeomAPI_Dir> theDirection,
-                                             const ListOfShape& theWires,
-                                             ListOfShape& theFaces);
+  GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
+                                                    const std::shared_ptr<GeomAPI_Dir> theDirection,
+                                                    const ListOfShape& theWires,
+                                                    ListOfShape& theFaces);
 
   /// \brief Return a plane for list of shapes if they are all planar.
   /// \param[in] theShapes shapes to find plane.
   /// \return plane where all shapes lie or empty ptr if they not planar.
-  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
+  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
 
   /// \brief Checks that vertex/edge is inside face or vertext inside wire.
   /// \param[in] theSubShape shape that should be inside.
   /// \param[in] theBaseShape base shape.
   /// \return true if edge inside the face.
-  GEOMALGOAPI_EXPORT bool isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
-                                                const std::shared_ptr<GeomAPI_Shape> theBaseShape);
+  GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
+                                                       const std::shared_ptr<GeomAPI_Shape> theBaseShape);
 };
 
 #endif