]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create Boolean operations
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 3 Sep 2014 08:27:04 +0000 (12:27 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 3 Sep 2014 08:27:04 +0000 (12:27 +0400)
18 files changed:
src/Config/Config_Keywords.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Boolean.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/boolean_widget.xml [new file with mode: 0644]
src/FeaturesPlugin/plugin-Features.xml
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h [new file with mode: 0644]
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetChoice.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetChoice.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.h
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/cut_shape.png [new file with mode: 0644]
src/PartSet/icons/cut_tool.png [new file with mode: 0644]

index 434857827fbf6137ef20dd5c78d6a4b15ef85899..d1569170068bf06186a4cbd3db70d9f49a7bc5d4 100644 (file)
@@ -29,6 +29,7 @@ const static char* WDG_TOOLBOX_BOX = "box";
 const static char* WDG_SWITCH = "switch";
 const static char* WDG_SWITCH_CASE = "case";
 const static char* WDG_SELECTOR = "selector";
+const static char* WDG_CHOICE = "choice";
 
 //Specific widget containers
 const static char* WDG_POINT_SELECTOR = "point_selector";
index 29e08785f58924916f65681f27f06aeef3c09925..6d4cd90fcc66c3e561fcfe5e0b8a150eb830b298 100644 (file)
@@ -4,11 +4,13 @@ SET(PROJECT_HEADERS
     FeaturesPlugin.h
     FeaturesPlugin_Plugin.h
     FeaturesPlugin_Extrusion.h
+       FeaturesPlugin_Boolean.h
 )
 
 SET(PROJECT_SOURCES
     FeaturesPlugin_Plugin.cpp
     FeaturesPlugin_Extrusion.cpp
+       FeaturesPlugin_Boolean.cpp
 )
 
 ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
@@ -24,6 +26,7 @@ INCLUDE_DIRECTORIES(
 SET(XML_RESOURCES
   plugin-Features.xml
   extrusion_widget.xml
+  boolean_widget.xml
 )
 
 INSTALL(TARGETS FeaturesPlugin DESTINATION plugins)
diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
new file mode 100644 (file)
index 0000000..220b414
--- /dev/null
@@ -0,0 +1,53 @@
+// File:        FeaturesPlugin_Boolean.cpp
+// Created:     02 Sept 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include "FeaturesPlugin_Boolean.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_Boolean.h>
+
+using namespace std;
+
+FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
+{
+}
+
+void FeaturesPlugin_Boolean::initAttributes()
+{
+  data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeReference::type());
+  data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::type());
+  data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::type());
+}
+
+boost::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::string& theAttrName)
+{
+  boost::shared_ptr<ModelAPI_AttributeReference> aObjRef = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeReference>(data()->attribute(theAttrName));
+  if (aObjRef) {
+    boost::shared_ptr<ModelAPI_ResultBody> aConstr = boost::dynamic_pointer_cast<
+        ModelAPI_ResultBody>(aObjRef->value());
+    if (aConstr)
+      return aConstr->shape();
+  }
+  return boost::shared_ptr<GeomAPI_Shape>();
+}
+
+
+void FeaturesPlugin_Boolean::execute()
+{
+  boost::shared_ptr<GeomAPI_Shape> aObject = this->getShape(FeaturesPlugin_Boolean::OBJECT_ID());
+  if (!aObject)
+    return;
+
+  boost::shared_ptr<GeomAPI_Shape> aTool = this->getShape(FeaturesPlugin_Boolean::TOOL_ID());
+  if (!aTool)
+    return;
+
+  boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
+  aResult->store(GeomAlgoAPI_Boolean::makeCut(aObject, aTool));
+  setResult(aResult);
+}
\ No newline at end of file
diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h
new file mode 100644 (file)
index 0000000..d4b0e22
--- /dev/null
@@ -0,0 +1,63 @@
+// File:        FeaturesPlugin_Boolean.h
+// Created:     02 Sept 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef FeaturesPlugin_Cut_H_
+#define FeaturesPlugin_Cut_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+#include <GeomAPI_Shape.h>
+
+class FeaturesPlugin_Boolean : public ModelAPI_Feature
+{
+ public:
+  /// Extrusion kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_CUT_ID("Boolean");
+    return MY_CUT_ID;
+  }
+  /// attribute name of referenced object
+  inline static const std::string& OBJECT_ID()
+  {
+    static const std::string MY_OBJECT_ID("main_object");
+    return MY_OBJECT_ID;
+  }
+  /// attribute name of tool object
+  inline static const std::string& TOOL_ID()
+  {
+    static const std::string MY_TOOL_ID("tool_object");
+    return MY_TOOL_ID;
+  }
+  /// attribute name of operation type
+  inline static const std::string& TYPE_ID()
+  {
+    static const std::string MY_TOOL_ID("bool_type");
+    return MY_TOOL_ID;
+  }
+
+
+
+  /// Returns the kind of a feature
+  FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = FeaturesPlugin_Boolean::ID();
+    return MY_KIND;
+  }
+
+  /// Creates a new part document if needed
+  FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Use plugin manager for features creation
+  FeaturesPlugin_Boolean();
+
+private:
+  boost::shared_ptr<GeomAPI_Shape> getShape(const std::string& theAttrName);
+
+};
+
+#endif
index c84ddf680f65bf0731af7932c38e866c607d27d7..5c3fd3a4335c3beb3d5126536b28c03c9d392b96 100644 (file)
@@ -1,5 +1,6 @@
 #include "FeaturesPlugin_Plugin.h"
 #include "FeaturesPlugin_Extrusion.h"
+#include "FeaturesPlugin_Boolean.h"
 
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
@@ -19,6 +20,9 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID)
 {
   if (theFeatureID == FeaturesPlugin_Extrusion::ID()) {
     return FeaturePtr(new FeaturesPlugin_Extrusion);
+  } else
+  if (theFeatureID == FeaturesPlugin_Boolean::ID()) {
+    return FeaturePtr(new FeaturesPlugin_Boolean);
   }
   // feature of such kind is not found
   return FeaturePtr();
diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml
new file mode 100644 (file)
index 0000000..d0ee131
--- /dev/null
@@ -0,0 +1,16 @@
+<source>
+  <selector id="main_object" 
+    label="Main object" 
+    icon=":icons/cut_shape.png" 
+    tooltip="Select an object to cut"
+    activate="true"
+    shape_types="solid,shell"
+  />
+  <selector id="tool_object" 
+    label="Tool object" 
+    icon=":icons/cut_tool.png" 
+    tooltip="Select a tool"
+    activate="false"
+    shape_types="solid"
+  />
+</source>
index 783d373fa9a9116ee39fd751b0a1b5a65e56c444..c8fc1511b0a2d2834386c4499d2e983191acf330 100644 (file)
@@ -4,6 +4,9 @@
       <feature id="Extrusion" title="Extrusion" tooltip="Create a shape by extrusion of a contour" icon=":icons/extrusion.png">
           <source path="extrusion_widget.xml"/>
       </feature>
+      <feature id="Boolean" title="Boolean" tooltip="Performs boolean operations with shapes" icon=":icons/cut.png">
+          <source path="boolean_widget.xml"/>
+      </feature>
     </group>
-</workbench>  
+  </workbench>  
 </plugin>
index 135d2747055307f087dd94627e59b5ff62c82b5a..26b230a2539915657f15b626987b49e24c286ada 100644 (file)
@@ -11,6 +11,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_PointBuilder.h
     GeomAlgoAPI_SketchBuilder.h
     GeomAlgoAPI_Extrusion.h
+       GeomAlgoAPI_Boolean.h
 )
 
 SET(PROJECT_SOURCES
@@ -20,6 +21,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_PointBuilder.cpp
     GeomAlgoAPI_SketchBuilder.cpp
     GeomAlgoAPI_Extrusion.cpp
+       GeomAlgoAPI_Boolean.cpp
 )
 
 ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp
new file mode 100644 (file)
index 0000000..0f68186
--- /dev/null
@@ -0,0 +1,24 @@
+// File:        GeomAlgoAPI_Boolean.cpp
+// Created:     02 Sept 2014
+// Author:      Vitaly Smetannikov
+
+#include "GeomAlgoAPI_Boolean.h"
+
+#include <BRepAlgoAPI_Cut.hxx>
+
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeCut(
+  boost::shared_ptr<GeomAPI_Shape> theShape,
+  boost::shared_ptr<GeomAPI_Shape> theTool)
+{
+  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
+
+  BRepAlgoAPI_Cut aCut(aShape, aTool);
+  if (aCut.IsDone()) {
+    boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
+    aResult->setImpl(new TopoDS_Shape(aCut.Shape()));
+    return aResult;
+  }
+  return boost::shared_ptr<GeomAPI_Shape>();
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h
new file mode 100644 (file)
index 0000000..790e795
--- /dev/null
@@ -0,0 +1,29 @@
+// File:        GeomAlgoAPI_Boolean.h
+// Created:     02 Sept 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef GeomAlgoAPI_Boolean_H_
+#define GeomAlgoAPI_Boolean_H_
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+
+/**\class GeomAlgoAPI_Boolean
+ * \ingroup DataAlgo
+ * \brief Allows to perform of boolean operations
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_Boolean
+{
+ public:
+  /* \brief Creates cut boolean operation
+   * \param[in] theShape face or wire to be extruded
+   * \param[in] theTool  toole shape for boolean
+   * \return a solid as result of operation
+   */
+  static boost::shared_ptr<GeomAPI_Shape> makeCut(boost::shared_ptr<GeomAPI_Shape> theShape,
+                                                        boost::shared_ptr<GeomAPI_Shape> theTool);
+
+};
+
+#endif
index b21756a5c39ff3dc9c72c13d5cbfd6696a9308cc..19ba908e8235fd2b71c20885885321fd2fc69ea9 100644 (file)
@@ -25,6 +25,7 @@ SET(PROJECT_HEADERS
        ModuleBase_SelectionValidator.h
        ModuleBase_ISelection.h
        ModuleBase_ViewerPrs.h
+       ModuleBase_WidgetChoice.h
 )
 
 SET(PROJECT_SOURCES
@@ -44,6 +45,7 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetPoint2dDistance.cpp
        ModuleBase_WidgetValue.cpp
        ModuleBase_WidgetValueFeature.cpp
+       ModuleBase_WidgetChoice.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp
new file mode 100644 (file)
index 0000000..6a1c455
--- /dev/null
@@ -0,0 +1,64 @@
+// File:        ModuleBase_WidgetChoice.cpp
+// Created:     03 Sept 2014
+// Author:      Vitaly Smetannikov
+
+#include "ModuleBase_WidgetChoice.h"
+
+#include <Config_WidgetAPI.h>
+
+#include <QWidget>
+#include <QLayout>
+#include <QLabel>
+#include <QComboBox>
+
+ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, 
+                                                 const Config_WidgetAPI* theData, 
+                                                 const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+  myContainer = new QWidget(theParent);
+  QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
+  aLayout->setContentsMargins(0, 0, 0, 0);
+
+  QString aLabelText = QString::fromStdString(theData->widgetLabel());
+  QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+  myLabel = new QLabel(aLabelText, myContainer);
+  myLabel->setPixmap(QPixmap(aLabelIcon));
+  aLayout->addWidget(myLabel);
+
+  myCombo = new QComboBox(myContainer);
+  aLayout->addWidget(myCombo);
+  connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
+}
+
+ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
+{
+}
+  
+bool ModuleBase_WidgetChoice::storeValue() const
+{
+  return true;
+}
+
+bool ModuleBase_WidgetChoice::restoreValue()
+{
+  return true;
+}
+
+bool ModuleBase_WidgetChoice::focusTo()
+{
+  myCombo->setFocus();
+  return true;
+}
+
+QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
+{
+  QList<QWidget*> aControls;
+  aControls.append(myLabel);
+  aControls.append(myCombo);
+  return aControls;
+}
+
+void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
+{
+}
\ No newline at end of file
diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.h b/src/ModuleBase/ModuleBase_WidgetChoice.h
new file mode 100644 (file)
index 0000000..15a9505
--- /dev/null
@@ -0,0 +1,52 @@
+// File:        ModuleBase_WidgetChoice.h
+// Created:     03 Sept 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef ModuleBase_WidgetChoice_H
+#define ModuleBase_WidgetChoice_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+class QWidget;
+class QLabel;
+class QComboBox;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetChoice : public ModuleBase_ModelWidget
+{
+Q_OBJECT
+ public:
+  ModuleBase_WidgetChoice(QWidget* theParent, const Config_WidgetAPI* theData, 
+                          const std::string& theParentId);
+
+  virtual ~ModuleBase_WidgetChoice();
+  
+  /// Saves the internal parameters to the given feature
+  /// \param theObject a model feature to be changed
+  virtual bool storeValue() const;
+
+  virtual bool restoreValue();
+
+  virtual bool focusTo();
+
+  /// Returns the internal parent wiget control, that can be shown anywhere
+  /// \returns the widget
+  QWidget* getControl() const
+  {
+    return myContainer;
+  }
+
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+
+private slots:
+  void onCurrentIndexChanged(int theIndex);
+
+private:
+  QWidget* myContainer;
+  QLabel* myLabel;
+  QComboBox* myCombo;
+};
+
+#endif
index ff187372cba1b6fe19dc775ae560d1380d20e665..35cb90e189895d04b7bbe8261dd785bfc6b77f97 100644 (file)
@@ -74,6 +74,10 @@ ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent,
   myTextLine->setToolTip(aToolTip);
   myTextLine->installEventFilter(this);
 
+  myBasePalet = myTextLine->palette();
+  myInactivePalet = myBasePalet;
+  myInactivePalet.setBrush(QPalette::Base, QBrush(Qt::gray, Qt::Dense6Pattern));
+
   aLayout->addWidget(myTextLine);
 
   myActivateBtn = new QToolButton(myContainer);
@@ -165,6 +169,7 @@ void ModuleBase_WidgetSelector::onSelectionChanged()
       myTextLine->setText("");
     }
     emit valuesChanged();
+    emit focusOutWidget(this);
   }
 }
 
@@ -181,15 +186,13 @@ bool ModuleBase_WidgetSelector::isAccepted(const ObjectPtr theResult) const
 
   TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
   if (aShapeType == TopAbs_COMPOUND) {
-    foreach (QString aType, myShapeTypes)
-    {
+    foreach (QString aType, myShapeTypes) {
       TopExp_Explorer aEx(aShape, shapeType(aType));
       if (aEx.More())
         return true;
     }
   } else {
-    foreach (QString aType, myShapeTypes)
-    {
+    foreach (QString aType, myShapeTypes) {
       if (shapeType(aType) == aShapeType)
         return true;
     }
@@ -237,7 +240,11 @@ void ModuleBase_WidgetSelector::enableOthersControls(bool toEnable) const
 void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
 {
   enableOthersControls(!toActivate);
-  myTextLine->setEnabled(toActivate);
+  //myTextLine->setEnabled(toActivate);
+  if (toActivate)
+    myTextLine->setPalette(myBasePalet);
+  else
+    myTextLine->setPalette(myInactivePalet);
 
   if (toActivate)
     connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
@@ -263,3 +270,10 @@ void ModuleBase_WidgetSelector::raisePanel() const
     aTabWgt->raise();
   }
 }
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::focusTo()
+{
+  myActivateBtn->setChecked(true);
+  return true;
+}
index 574ae0e8b5112c96598dd1a39e8ebe0e62415291..0eba6cdee057d3245af29079e46ab254f1ed12af 100644 (file)
@@ -13,6 +13,7 @@
 #include <TopAbs_ShapeEnum.hxx>
 
 #include <QStringList>
+#include <QPalette>
 
 class Config_WidgetAPI;
 class QWidget;
@@ -36,6 +37,8 @@ Q_OBJECT
 
   virtual bool restoreValue();
 
+  virtual bool focusTo();
+
   /// Returns the internal parent wiget control, that can be shown anywhere
   /// \returns the widget
   QWidget* getControl() const
@@ -91,6 +94,9 @@ Q_OBJECT
 
   ObjectPtr mySelectedObject;
   QStringList myShapeTypes;
+
+  QPalette myBasePalet;
+  QPalette myInactivePalet;
 };
 
 #endif
index 2944e95ccc9db899029e95ed7304660c68a884f8..c65485e76cf116e60479afadbaee3702860f6aa5 100644 (file)
@@ -9,6 +9,8 @@
      <file>icons/remove.png</file>
      <file>icons/extrusion.png</file>
      <file>icons/cut.png</file>
+     <file>icons/cut_tool.png</file>
+     <file>icons/cut_shape.png</file>
      <file>icons/fusion.png</file>
      <file>icons/revol.png</file>
      <file>icons/common.png</file>
diff --git a/src/PartSet/icons/cut_shape.png b/src/PartSet/icons/cut_shape.png
new file mode 100644 (file)
index 0000000..618d744
Binary files /dev/null and b/src/PartSet/icons/cut_shape.png differ
diff --git a/src/PartSet/icons/cut_tool.png b/src/PartSet/icons/cut_tool.png
new file mode 100644 (file)
index 0000000..0c034de
Binary files /dev/null and b/src/PartSet/icons/cut_tool.png differ