]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
multi selector controls for boolean feature
authornds <natalia.donis@opencascade.com>
Fri, 22 May 2015 12:19:43 +0000 (15:19 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 22 May 2015 12:20:10 +0000 (15:20 +0300)
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_Boolean.h
src/FeaturesPlugin/boolean_widget.xml
src/GeomAPI/GeomAPI_Face.cpp
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp

index 2932d5e5cce410fa963f068e5579554a3dcfc13c..f52353397cd33038c352ef1a98cbcfb3280e55ff 100644 (file)
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <GeomAlgoAPI_Boolean.h>
 using namespace std;
 
+//#define DEBUG_ONE_OBJECT
+
 #define FACE 4
 #define _MODIFY_TAG 1
 #define _DELETED_TAG 2
@@ -24,8 +27,25 @@ FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
 void FeaturesPlugin_Boolean::initAttributes()
 {
   data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::typeId());
+
+#ifdef DEBUG_ONE_OBJECT
   data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::typeId());
+#else
+  AttributeSelectionListPtr aSelection = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
+    FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+  // extrusion works with faces always
+  aSelection->setSelectionType("SOLID");
+#endif
+
+#ifdef DEBUG_ONE_OBJECT
   data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::typeId());
+#else
+  aSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
+    FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+  // extrusion works with faces always
+  aSelection->setSelectionType("SOLID");
+#endif
 }
 
 std::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::string& theAttrName)
@@ -49,12 +69,41 @@ void FeaturesPlugin_Boolean::execute()
   if (!aTypeAttr)
     return;
   int aType = aTypeAttr->value();
-
+#ifdef DEBUG_ONE_OBJECT
   std::shared_ptr<GeomAPI_Shape> anObject = this->getShape(FeaturesPlugin_Boolean::OBJECT_ID());
+#else
+  std::shared_ptr<GeomAPI_Shape> anObject;
+  {
+    AttributeSelectionListPtr anObjects = selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
+    if (anObjects->size() == 0)
+      return;
+
+    // Getting bounding planes.
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = anObjects->value(0);
+    if (!anObjRef.get())
+      return;
+    anObject = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  }
+#endif
   if (!anObject)
     return;
 
+#ifdef DEBUG_ONE_OBJECT
   std::shared_ptr<GeomAPI_Shape> aTool = this->getShape(FeaturesPlugin_Boolean::TOOL_ID());
+#else
+  std::shared_ptr<GeomAPI_Shape> aTool;
+  {
+    AttributeSelectionListPtr anObjects = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
+    if (anObjects->size() == 0)
+      return;
+
+    // Getting bounding planes.
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = anObjects->value(0);
+    if (!anObjRef.get())
+      return;
+    aTool = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  }
+#endif
   if (!aTool)
     return;
 
index 65ad15d2e99f2ba424a3ebb50e75681d613d8713..53023300a90359148b8fccf7df6fde8152739e7f 100644 (file)
@@ -29,6 +29,12 @@ public:
     return MY_ID;
   }
   /// attribute name of referenced object
+  inline static const std::string& OBJECT_LIST_ID()
+  {
+    static const std::string MY_OBJECT_LIST_ID("main_objects");
+    return MY_OBJECT_LIST_ID;
+  }
+  /// attribute name of referenced object
   inline static const std::string& OBJECT_ID()
   {
     static const std::string MY_OBJECT_ID("main_object");
@@ -40,6 +46,12 @@ public:
     static const std::string MY_TOOL_ID("tool_object");
     return MY_TOOL_ID;
   }
+  /// attribute name of tool object
+  inline static const std::string& TOOL_LIST_ID()
+  {
+    static const std::string MY_TOOL_LIST_ID("tool_objects");
+    return MY_TOOL_LIST_ID;
+  }
   /// attribute name of operation type
   inline static const std::string& TYPE_ID()
   {
index 9a6e83da90e1e76fd50c922146d840aaacaf55dc..e1443e531c8ff456970a73001450b6e18f90a8bd 100644 (file)
@@ -1,24 +1,40 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <shape_selector id="main_object" 
+  <!--<shape_selector id="main_object" 
     label="Main object" 
     icon=":icons/cut_shape.png" 
     tooltip="Select an object solid"
     shape_types="solid shell"
     concealment="true"
+  />-->
+  <multi_selector id="main_objects" 
+    label="Main object" 
+    icon=":icons/cut_shape.png" 
+    tooltip="Select an object solid"
+    type_choice="Solids"
+    concealment="true"
   />
-  <shape_selector id="tool_object" 
+  <multi_selector id="tool_objects" 
+    label="Tool object" 
+    icon=":icons/cut_tool.png" 
+    tooltip="Select a tool solid"
+    type_choice="Solids"
+    concealment="true" >
+       <validator id="PartSet_DifferentObjects"/>
+  </multi_selector>
+  <!--<shape_selector id="tool_object" 
     label="Tool object" 
     icon=":icons/cut_tool.png" 
     tooltip="Select a tool solid"
     shape_types="solid"
     concealment="true" >
        <validator id="PartSet_DifferentObjects"/>
-  </shape_selector>
+  </shape_selector>-->
   <choice id="bool_type" 
     label="Type" 
     tooltip="Type of boolean operation"
     string_list="Cut Fuse Common"
+    default="0"
   />
 </source>
index 2055bdc6dac6951b35fb2e822c1eb46b5eee628b..b9dbd45df2f45bf8127e0b0d8f18a20ff43d9dfa 100644 (file)
@@ -16,6 +16,7 @@
 #include <BRepAdaptor_Surface.hxx>
 #include <Geom_Surface.hxx>
 #include <Geom_Plane.hxx>
+#include <GeomLib_IsPlanarSurface.hxx>
 
 GeomAPI_Face::GeomAPI_Face()
   : GeomAPI_Shape()
@@ -64,9 +65,8 @@ bool GeomAPI_Face::isPlanar() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
-  if (aSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
-    return true;
-  return false;
+  GeomLib_IsPlanarSurface isPlanar(aSurf);
+  return isPlanar.IsPlanar();
 }
 
 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
index fab62c1818d52fe14dda125ba6080fda343699d8..d03b76169da3c224762f41fcdb5057e3885333cb 100644 (file)
@@ -11,6 +11,7 @@
 #include <TopoDS.hxx>
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
+#include <GeomLib_IsPlanarSurface.hxx>
 
 
 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
@@ -70,11 +71,13 @@ std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
   if (aSurf.IsNull())
     return aResult;  // no surface
-  Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
-  if (aPlane.IsNull())
-    return aResult;  // not planar
+  GeomLib_IsPlanarSurface isPlanar(aSurf);
+  if(!isPlanar.IsPlanar()) {
+    return aResult;
+  }
+  gp_Pln aPln = isPlanar.Plan();
   double aA, aB, aC, aD;
-  aPlane->Coefficients(aA, aB, aC, aD);
+  aPln.Coefficients(aA, aB, aC, aD);
   aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
   return aResult;
 }