]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: selection processing...
authornds <nds@opencascade.com>
Mon, 21 Mar 2016 10:32:07 +0000 (13:32 +0300)
committerdbv <dbv@opencascade.com>
Fri, 25 Mar 2016 15:49:34 +0000 (18:49 +0300)
src/FeaturesPlugin/extrusion_widget.xml
src/PartSet/PartSet_WidgetSketchCreator.cpp
src/PartSet/PartSet_WidgetSketchCreator.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h

index b6425362b8456da6eec3e91492cd237b64447b27..09462cf8e0f2c8dc4ae15345de5c74f08a14ce1b 100644 (file)
@@ -9,7 +9,7 @@ Extrusion will be filled with them"
     icon=":icons/sketch.png"
     use_body="false"
     tooltip="Create or edit a sketch"
-    shape_types="vertex edge face">
+    shape_types="vertex edge face wire objects">
   </sketch_launcher>
   <toolbox id="CreationMethod">
     <box id="BySizes" title="By sizes" icon=":icons/dimension_up_down_32x32.png">
index 874d917b1bd4990d19aa6c678323e23297775b09..972a0e7a894137502ae9bd3024c684c5e962c8dc 100644 (file)
@@ -115,12 +115,12 @@ bool PartSet_WidgetSketchCreator::storeValueCustom() const
 
 void PartSet_WidgetSketchCreator::activateCustom()
 {
-  if (isSelectionMode()) {
-    ModuleBase_WidgetSelector::activateCustom();
+  //if (isSelectionMode()) {
+  //  ModuleBase_WidgetSelector::activateCustom();
     //connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
 
     //setVisibleSelectionControl(true);
-  }
+  //}
   //else {
   //  setVisibleSelectionControl(false);
   //  emit focusOutWidget(this);
@@ -180,16 +180,16 @@ void PartSet_WidgetSketchCreator::onSelectionChanged()
 {
   QList<ModuleBase_ViewerPrs> aSelected = getFilteredSelected();
 
-  if (aSelected.size() == 1) { // plane or planar face of not sketch object
-    startSketchOperation(aSelected.front());
+  if (startSketchOperation(aSelected)) {
+
   }
-  else if (aSelected.size() > 1) {
+  else {// if (aSelected.size() > 1) {
     QList<ModuleBase_ViewerPrs>::const_iterator anIt = aSelected.begin(), aLast = aSelected.end();
-    bool aProcessed;
+    bool aProcessed = false;
     for (; anIt != aLast; anIt++) {
       ModuleBase_ViewerPrs aValue = *anIt;
       if (isValidInFilters(aValue))
-        aProcessed = setSelectionCustom(aValue);
+        aProcessed = setSelectionCustom(aValue) || aProcessed;
     }
     if (aProcessed) {
       emit valuesChanged();
@@ -217,15 +217,23 @@ void PartSet_WidgetSketchCreator::setObject(ObjectPtr theSelectedObject,
     }
   }
 }
-void PartSet_WidgetSketchCreator::onStarted()
+//void PartSet_WidgetSketchCreator::onStarted()
+//{
+//  disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
+//}
+
+bool PartSet_WidgetSketchCreator::startSketchOperation(const QList<ModuleBase_ViewerPrs>& theValues)
 {
-  disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
+  bool aSketchStarted = false;
 
-  setVisibleSelectionControl(true);
-}
+  if (theValues.size() != 1)
+    return aSketchStarted;
 
-void PartSet_WidgetSketchCreator::startSketchOperation(const ModuleBase_ViewerPrs& theValue)
-{
+  ModuleBase_ViewerPrs aValue = theValues.front();
+  if (!PartSet_WidgetSketchLabel::canFillSketch(aValue))
+    return aSketchStarted;
+
+  aSketchStarted = true;
   // Check that model already has bodies
   /*XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
   XGUI_Workshop* aWorkshop = aConnector->workshop();
@@ -256,7 +264,7 @@ void PartSet_WidgetSketchCreator::startSketchOperation(const ModuleBase_ViewerPr
     FeaturePtr aPreviousCurrentFeature = aDoc->currentFeature(false);
     FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
 
-    PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(aSketch, theValue);
+    PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(aSketch, aValue);
 
     aDoc->setCurrentFeature(aPreviousCurrentFeature, false);
 
@@ -277,22 +285,27 @@ void PartSet_WidgetSketchCreator::startSketchOperation(const ModuleBase_ViewerPr
     ModuleBase_Operation* aOp = myModule->workshop()->currentOperation();
     aOp->abort();
   }*/
+  return aSketchStarted;
 }
 
 bool PartSet_WidgetSketchCreator::focusTo()
 {
   if (isSelectionMode()) {
+    setVisibleSelectionControl(true);
+
     //CompositeFeaturePtr aCompFeature = 
     //   std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
     // if (aCompFeature->numberOfSubs() == 0)
     //   return ModuleBase_ModelWidget::focusTo(); 
-    connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+    //connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
     // we need to call activate here as the widget has no focus accepted controls
     // if these controls are added here, activate will happens automatically after focusIn()
-    activate();
+    ModuleBase_WidgetSelector::activateCustom();
     return true;
   }
   else {
+    setVisibleSelectionControl(false);
+
     connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*)));
     SessionPtr aMgr = ModelAPI_Session::get();
     // Open transaction that is general for the previous nested one: it will be closed on nested commit
index e14352a0c3e3efdd7a4e073a8466cd9fdc80078e..a03e7102136696e90305b7fd01ae53494f299518 100644 (file)
@@ -87,14 +87,15 @@ protected slots:
   virtual void onSelectionChanged();
 
 private slots:
-  void onStarted();
+  //void onStarted();
 
   void onResumed(ModuleBase_Operation* theOp);
 
 private:
   /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
-  /// \param theValue a selected object to obtain a plane for sketch
-  void startSketchOperation(const ModuleBase_ViewerPrs& theValue);
+  /// \param theValues a selection list
+  /// \return true if the sketch is started
+  bool startSketchOperation(const QList<ModuleBase_ViewerPrs>& theValues);
 
 private:
   std::string myAttributeListID;
index ea65b9315e0bf753fa99ddbeec80327aa47f1b80..4fdd0033ad52bb141add2d4904f151cb5eac6cfa 100644 (file)
@@ -320,6 +320,32 @@ bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrs& t
   return fillSketchPlaneBySelection(feature(), thePrs);
 }
 
+#include <GeomAPI_Face.h>
+bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrs& thePrs)
+{
+  bool aCanFillSketch = true;
+  // avoid any selection on sketch object
+  ObjectPtr anObject = thePrs.object();
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+  if (aResult.get()) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
+    if (aFeature->getKind() == SketchPlugin_Sketch::ID())
+      aCanFillSketch = false;
+  }
+  // check plane or planar face of any non-sketch object
+  if (aCanFillSketch) {
+    const TopoDS_Shape aShape = thePrs.shape();
+    if (aShape.ShapeType() == TopAbs_FACE) {
+      std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face());
+      aGeomFace->setImpl(new TopoDS_Shape(aShape));
+      aCanFillSketch = aGeomFace.get() && aGeomFace->isPlanar();
+    }
+    else
+      aCanFillSketch = false;
+  }
+  return aCanFillSketch;
+}
+
 bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const FeaturePtr& theFeature,
                                                            const ModuleBase_ViewerPrs& thePrs)
 {
index ff6689d1cb74bc333cb99596c50cdf544cb3581f..956b06ee0ec71a8ae29c5de77187b733808cba22 100644 (file)
@@ -79,6 +79,8 @@ public:
   virtual void setHighlighted(bool) { /*do nothing*/ };
   virtual void enableFocusProcessing();
 
+  static bool canFillSketch(const ModuleBase_ViewerPrs& thePrs);
+
   static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
                                          const ModuleBase_ViewerPrs& thePrs);