Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: extrusion is a compos...
authornds <nds@opencascade.com>
Thu, 17 Mar 2016 14:05:11 +0000 (17:05 +0300)
committerdbv <dbv@opencascade.com>
Wed, 6 Apr 2016 10:19:56 +0000 (13:19 +0300)
src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.h
src/FeaturesPlugin/extrusion_widget.xml
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp [new file with mode: 0755]
src/PartSet/PartSet_WidgetMultiSelectorComposite.h [new file with mode: 0755]

index 628773d414e90d5a7dc635f37054a85e5665bf68..5f7354120f011370e2669ccc646db8877724455e 100644 (file)
@@ -116,8 +116,11 @@ void FeaturesPlugin_CompositeSketch::execute()
     return;
   }
 
-  if (!selection(SKETCH_SELECTION_ID())->isInitialized() || selection(SKETCH_SELECTION_ID())->context() != aSketchRes) {
-    selection(SKETCH_SELECTION_ID())->setValue(aSketchRes, std::shared_ptr<GeomAPI_Shape>());
+  /// feature extrusion does not have the next attribute
+  if (data()->attribute(SKETCH_SELECTION_ID()).get()) {
+    if (!selection(SKETCH_SELECTION_ID())->isInitialized() || selection(SKETCH_SELECTION_ID())->context() != aSketchRes) {
+      selection(SKETCH_SELECTION_ID())->setValue(aSketchRes, std::shared_ptr<GeomAPI_Shape>());
+    }
   }
   int aSketchFacesNum = aConstruction->facesNum();
   if(aSketchFacesNum == 0) {
index 1a1036a1181fa38917156815cecab04c2a065eec..36ca2939f9802e11e21e1f159d22488b75e7555c 100644 (file)
@@ -14,6 +14,7 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeReference.h>
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_Prism.h>
@@ -34,6 +35,9 @@ void FeaturesPlugin_Extrusion::initAttributes()
     LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
   // extrusion works with faces always
   aSelection->setSelectionType("FACE");
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+                                    FeaturesPlugin_Extrusion::LIST_ID());
+
 
   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
 
@@ -48,14 +52,28 @@ void FeaturesPlugin_Extrusion::initAttributes()
 
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
+
+  // Composite Sketch attribute
+  data()->addAttribute(FeaturesPlugin_CompositeSketch::SKETCH_OBJECT_ID(),
+                       ModelAPI_AttributeReference::typeId());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+                       FeaturesPlugin_CompositeSketch::SKETCH_OBJECT_ID());
 }
 
 //=================================================================================================
 void FeaturesPlugin_Extrusion::execute()
 {
+  /// feature extrusion does not have the next attribute
+  AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+  if (aFacesSelectionList.get() && !aFacesSelectionList->isInitialized()) {
+    AttributeReferencePtr aSketchAttr = reference(SKETCH_OBJECT_ID());
+    if (aSketchAttr.get() && aSketchAttr->isInitialized())
+      setSketchObjectToList();
+  }
+
   // Getting faces.
   ListOfShape aFacesList;
-  AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+  //AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
   for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) {
     AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex);
     std::shared_ptr<GeomAPI_Shape> aFaceShape = aFaceSel->value();
@@ -204,3 +222,20 @@ void FeaturesPlugin_Extrusion::loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo,
     theResultBody->generated(aFromFace, aStr.str(), aFromTag++);
   }
 }
+
+//=================================================================================================
+void FeaturesPlugin_Extrusion::setSketchObjectToList()
+{
+  std::shared_ptr<ModelAPI_Feature> aSketchFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
+                                                       reference(SKETCH_OBJECT_ID())->value());
+
+  if(aSketchFeature.get() && !aSketchFeature->results().empty()) {
+    ResultPtr aSketchRes = aSketchFeature->results().front();
+    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSketchRes);
+    if(aConstruction.get()) {
+      AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+      if (aFacesSelectionList.get() && aFacesSelectionList->size() == 0)
+        aFacesSelectionList->append(aSketchRes, std::shared_ptr<GeomAPI_Shape>());
+    }
+  }
+}
index 98c9af7c9ddf90f655fba32f66b2e9b8daf61df1..cc000508123be6cd07f2c2ce7666833e8f946664 100644 (file)
@@ -8,9 +8,10 @@
 #define FeaturesPlugin_Extrusion_H_
 
 #include <FeaturesPlugin.h>
-#include <ModelAPI_Feature.h>
 #include <GeomAlgoAPI_Prism.h>
 
+#include <FeaturesPlugin_CompositeSketch.h>
+
 class GeomAPI_Shape;
 class ModelAPI_ResultBody;
 
@@ -23,7 +24,7 @@ class ModelAPI_ResultBody;
  * bounding planes if they were set. Direction of extrusion is taken from the face
  * plane or if the bounding faces were set then it will be from the bottom to the top plane.
  */
-class FeaturesPlugin_Extrusion : public ModelAPI_Feature
+class FeaturesPlugin_Extrusion : public FeaturesPlugin_CompositeSketch
 {
  public:
   /// Extrusion kind
@@ -111,11 +112,23 @@ class FeaturesPlugin_Extrusion : public ModelAPI_Feature
 
   /// Use plugin manager for features creation
   FeaturesPlugin_Extrusion();
+
+protected:
+  /// Init attributes for extrusion.
+  virtual void initMakeSolidsAttributes() {};
+
+  /// Create solid from face with extrusion.
+  virtual void makeSolid(const std::shared_ptr<GeomAPI_Shape> theFace,
+                         std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape) {};
+
 private:
   /// Load Naming data structure of the feature to the document
   void loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo,
                     std::shared_ptr<ModelAPI_ResultBody> theResultBody,
                     std::shared_ptr<GeomAPI_Shape> theBasis);
+
+  /// Set the sub-object to list of exturusion base.
+  void setSketchObjectToList();
 };
 
 #endif
index 90a7b70785fd18477577bd0e36f68df2e20ff59d..82414a999db3b375c35ccf6377713d0afc60e748 100644 (file)
@@ -1,15 +1,21 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
+  <sketch_launcher id="sketch"
+    label="Sketch"
+    icon=":icons/sketch.png"
+    use_body="false"
+    tooltip="Create or edit a sketch">
+  </sketch_launcher>
   <toolbox id="CreationMethod">
     <box id="BySizes" title="By sizes" icon=":icons/dimension_up_down_32x32.png">
-      <multi_selector id="base"
+      <composite_multi_selector id="base"
         label="Select a sketch face"
         icon=":icons/sketch.png"
         tooltip="Select a sketch face"
         type_choice="Faces">
         <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
-      </multi_selector>
+      </composite_multi_selector>
       <groupbox>
         <doublevalue
           id="to_size"
       </groupbox>
     </box>
     <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted_32x32.png">
-      <multi_selector id="base"
+      <composite_multi_selector id="base"
         label="Select a sketch face"
         icon=":icons/sketch.png"
         tooltip="Select a sketch face"
         type_choice="Faces">
         <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
-      </multi_selector>
+      </composite_multi_selector>
       <groupbox title="From">
         <shape_selector id="from_object"
                         icon=":icons/plane.png"
index 2c0d2ed8f28123cb759f98f6804dd0ec63c4761a..17b1fdedc478608acca1e76a9d838be3299d3253 100644 (file)
@@ -18,6 +18,7 @@ SET(PROJECT_HEADERS
        PartSet_WidgetPoint2d.h
        PartSet_WidgetEditor.h
        PartSet_WidgetMultiSelector.h
+       PartSet_WidgetMultiSelectorComposite.h
        PartSet_WidgetPoint2dDistance.h
        PartSet_WidgetPoint2DFlyout.h
        PartSet_WidgetShapeSelector.h
@@ -43,6 +44,7 @@ SET(PROJECT_SOURCES
        PartSet_Validators.cpp
        PartSet_WidgetEditor.cpp
        PartSet_WidgetMultiSelector.cpp
+       PartSet_WidgetMultiSelectorComposite.cpp
        PartSet_WidgetPoint2d.cpp
        PartSet_WidgetPoint2dDistance.cpp
        PartSet_WidgetPoint2DFlyout.cpp
index f580bcb11c1c2227d4564a45580fbf88cec96160..53ae4b0982814d6db07aeb5c8639026817681009 100755 (executable)
@@ -9,6 +9,7 @@
 #include "PartSet_WidgetPoint2DFlyout.h"
 #include "PartSet_WidgetShapeSelector.h"
 #include "PartSet_WidgetMultiSelector.h"
+#include "PartSet_WidgetMultiSelectorComposite.h"
 #include "PartSet_WidgetEditor.h"
 #include "PartSet_WidgetFileSelector.h"
 #include "PartSet_WidgetSketchCreator.h"
@@ -677,7 +678,12 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
                           new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
     aWgt = aShapeSelectorWgt;
-  } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
+  } else if (theType == "composite_multi_selector") {
+    PartSet_WidgetMultiSelectorComposite* aShapeSelectorWgt =
+                 new PartSet_WidgetMultiSelectorComposite(theParent, aWorkshop, theWidgetApi);
+    aWgt = aShapeSelectorWgt;
+  }
+  else if (theType == WDG_DOUBLEVALUE_EDITOR) {
     aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
   } else if (theType == "export_file_selector") {
     aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
diff --git a/src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp b/src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp
new file mode 100755 (executable)
index 0000000..32bd055
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_WidgetMultiSelectorComposite.cpp
+// Created:     17 Mar 2016
+// Author:      Natalia Ermolaeva
+
+#include "PartSet_WidgetMultiSelectorComposite.h"
+
+PartSet_WidgetMultiSelectorComposite::PartSet_WidgetMultiSelectorComposite(QWidget* theParent,
+                                                         ModuleBase_IWorkshop* theWorkshop,
+                                                         const Config_WidgetAPI* theData)
+: ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData)
+{
+}
+
+PartSet_WidgetMultiSelectorComposite::~PartSet_WidgetMultiSelectorComposite()
+{
+}
+
+bool PartSet_WidgetMultiSelectorComposite::focusTo()
+{
+  bool aCanSetFocus = true;
+  CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+  if (aComposite.get())
+    aCanSetFocus = aComposite->numberOfSubs() == 0;
+
+  // disable widget controls
+  if (!aCanSetFocus) {
+    disableControls();
+  }
+
+  return aCanSetFocus;
+}
+
+void PartSet_WidgetMultiSelectorComposite::disableControls()
+{
+  QList<QWidget*> aMyControls = getControls();
+  foreach(QWidget*  eachControl, aMyControls) {
+    eachControl->setFocusPolicy(Qt::NoFocus);
+    eachControl->setEnabled(false);
+  }
+}
diff --git a/src/PartSet/PartSet_WidgetMultiSelectorComposite.h b/src/PartSet/PartSet_WidgetMultiSelectorComposite.h
new file mode 100755 (executable)
index 0000000..62afac3
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_WidgetMultiSelectorComposite.h
+// Created:     17 Mar 2016
+// Author:      Natalia Ermolaeva
+
+#ifndef PartSet_WidgetMultiSelectorComposite_H
+#define PartSet_WidgetMultiSelectorComposite_H
+
+#include "PartSet.h"
+
+#include <ModuleBase_WidgetMultiSelector.h>
+
+#include <ModelAPI_CompositeFeature.h>
+
+/**
+* \ingroup Modules
+* Customosation of ModuleBase_WidgetMultiSelector in order to provide 
+* working with sketch specific objects and creation of external objects.
+*/
+class PARTSET_EXPORT PartSet_WidgetMultiSelectorComposite: public ModuleBase_WidgetMultiSelector
+{
+Q_OBJECT
+ public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theWorkshop instance of workshop interface
+  /// \param theData the widget configuation. The attribute of the model widget is obtained from
+  PartSet_WidgetMultiSelectorComposite(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+                              const Config_WidgetAPI* theData);
+
+  virtual ~PartSet_WidgetMultiSelectorComposite();
+
+  /// Set focus to the first control of the current widget. The focus policy of the control is checked.
+  /// If the widget has the NonFocus focus policy, it is skipped.
+  /// \return the state whether the widget can accept the focus
+  virtual bool focusTo();
+
+private:
+  /// Disable controls by setting them focus policy NoFocus and disabling them
+  void disableControls();
+};
+
+#endif
\ No newline at end of file