Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: selection processing...
authornds <nds@opencascade.com>
Fri, 18 Mar 2016 08:59:47 +0000 (11:59 +0300)
committerdbv <dbv@opencascade.com>
Wed, 6 Apr 2016 10:19:57 +0000 (13:19 +0300)
src/FeaturesPlugin/extrusion_widget.xml
src/ModuleBase/ModuleBase_WidgetSelector.h
src/PartSet/PartSet_WidgetSketchCreator.cpp
src/PartSet/PartSet_WidgetSketchCreator.h

index ac410cf69cfd5d31ee70164f4f586fb6718fb397..b6425362b8456da6eec3e91492cd237b64447b27 100644 (file)
@@ -2,6 +2,7 @@
 
 <source>
   <sketch_launcher id="sketch"
+    attribute_list_id="base"
     label="Select: 1. Planar face of non-sketch object or a plane. Sketch creation will be started.
 2. An existing sketch face or contour. Extrusion will be filled with them. 3.A shape on existing result: wires/edge/vertices.
 Extrusion will be filled with them"
index d2fbdeb08dcc660d5204e980440c6e8dbe8ceab6..d095512a4968e71ddff2a025539ead306ccde116 100755 (executable)
@@ -58,24 +58,29 @@ Q_OBJECT
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
- private slots:
-   /// Slot which is called on selection event
-  void onSelectionChanged();
+// NDS: protected is temporary
+protected slots:
+  /// Slot which is called on selection event
+  // NDS: virtual is temporary
+  virtual void onSelectionChanged();
 
  protected:
   /// Update focus after the attribute value change
+  // NDS: has body is temporary
    virtual void updateFocus() {};
 
   /// Return the attribute values wrapped in a list of viewer presentations
   /// \return a list of viewer presentations, which contains an attribute result and
   /// a shape. If the attribute do not uses the shape, it is empty
-   virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
+  // NDS: has body is temporary
+  virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
 
   /// Retunrs a list of possible shape types
   /// \return a list of shapes
   virtual QIntList getShapeTypes() const = 0;
 
   /// Computes and updates name of selected object in the widget
+  // NDS: has body is temporary
   virtual void updateSelectionName() {};
 
   /// Store the values to the model attribute of the widget. It casts this attribute to
@@ -83,7 +88,7 @@ Q_OBJECT
   /// \param theSelectedObject an object
   /// \param theShape a selected shape, which is used in the selection attribute
   /// \return true if it is succeed
-  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) {};
+  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) = 0;
 
   /// The methiod called when widget is activated
   virtual void activateCustom();
index 22e839ce5cc20816300c6aa9be9e43bd327c2746..71069fe365f10c0bb4e79025aaf201f3eda19782 100644 (file)
@@ -120,10 +120,10 @@ void PartSet_WidgetSketchCreator::activateCustom()
 
     //setVisibleSelectionControl(true);
   }
-  else {
-    setVisibleSelectionControl(false);
-    emit focusOutWidget(this);
-  }
+  //else {
+  //  setVisibleSelectionControl(false);
+  //  emit focusOutWidget(this);
+  //}
 }
 
 void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelectionControl)
@@ -141,6 +141,8 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec
     else { // hide current control
       if (aWidget == this)
         aWidget->setVisible(false);
+      else
+        aWidget->setVisible(true);
     }
   }
 }
@@ -173,15 +175,58 @@ bool PartSet_WidgetSketchCreator::isSelectionMode() const
   return !aHasValueInList;//aHasSub || aHasValueInList;
 }
 
+void PartSet_WidgetSketchCreator::onSelectionChanged()
+{
+  QList<ModuleBase_ViewerPrs> aSelected = getFilteredSelected();
+
+  if (aSelected.size() == 1) { // plane or planar face of not sketch object
+    startSketchOperation();
+  }
+  else if (aSelected.size() > 1) {
+    QList<ModuleBase_ViewerPrs>::const_iterator anIt = aSelected.begin(), aLast = aSelected.end();
+    bool aProcessed;
+    for (; anIt != aLast; anIt++) {
+      ModuleBase_ViewerPrs aValue = *anIt;
+      if (isValidInFilters(aValue))
+        aProcessed = setSelectionCustom(aValue);
+    }
+    if (aProcessed) {
+      emit valuesChanged();
+      updateObject(myFeature);
+      setVisibleSelectionControl(false);
+      emit focusOutWidget(this);
+    }
+  }
+}
+
+//********************************************************************
+void PartSet_WidgetSketchCreator::setObject(ObjectPtr theSelectedObject,
+                                            GeomShapePtr theShape)
+{
+  std::string anAttributeId = myAttributeListID;
+  DataPtr aData = myFeature->data();
+  AttributePtr anAttribute = aData->attribute(anAttributeId);
+  if (anAttribute.get()) {
+    std::string aType = anAttribute->attributeType();
+    if (aType == ModelAPI_AttributeSelectionList::typeId()) {
+      AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(anAttributeId);
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+      if (!aSelectionListAttr->isInList(aResult, theShape, myIsInValidate))
+        aSelectionListAttr->append(aResult, theShape, myIsInValidate);
+    }
+  }
+}
 void PartSet_WidgetSketchCreator::onStarted()
 {
   disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
 
   setVisibleSelectionControl(true);
+}
 
-  /*
+void PartSet_WidgetSketchCreator::startSketchOperation()
+{
   // Check that model already has bodies
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+  /*XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
   XGUI_Workshop* aWorkshop = aConnector->workshop();
   XGUI_Displayer* aDisp = aWorkshop->displayer();
   QObjectPtrList aObjList = aDisp->displayedObjects();
@@ -195,9 +240,9 @@ void PartSet_WidgetSketchCreator::onStarted()
         break;
       }
     }
-  }
+  }*/
 
-  if (aHasBody) {
+  //if (aHasBody) {
     // Launch Sketch operation
     CompositeFeaturePtr aCompFeature = 
       std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
@@ -218,7 +263,8 @@ void PartSet_WidgetSketchCreator::onStarted()
       aFOperation->setFeature(aSketch);
     myModule->sendOperation(aFOperation);
     //connect(anOperation, SIGNAL(aborted()), aWorkshop->operationMgr(), SLOT(abortAllOperations()));
-  } else {
+  //}
+  /* else {
     // Break current operation
     std::string anOperationName = feature()->getKind();
     QString aTitle = tr( anOperationName.c_str() );
@@ -237,6 +283,9 @@ bool PartSet_WidgetSketchCreator::focusTo()
     // if (aCompFeature->numberOfSubs() == 0)
     //   return ModuleBase_ModelWidget::focusTo(); 
     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();
     return true;
   }
   else {
index f52a0f1fa3f06d68822772db56a2930e1e3f2e0b..7349d16159cefd3b2b3c1fdc1cc3a32be7a06043 100644 (file)
@@ -68,17 +68,33 @@ protected:
   /// \return a list of shapes
   virtual QIntList getShapeTypes() const;
 
+  /// Store the values to the model attribute of the widget. It casts this attribute to
+  /// the specific type and set the given values
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  /// \return true if it is succeed
+  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+
 private:
   /// Returns true if the selection mode is active. This is when composition feature has no
   ///  a sub-object and the attribute list is empty
   /// \return boolean value
   bool isSelectionMode() const;
 
+protected slots:
+  /// Slot which is called on selection event
+  // NDS: virtual is temporary
+  virtual void onSelectionChanged();
+
 private slots:
   void onStarted();
 
   void onResumed(ModuleBase_Operation* theOp);
 
+private:
+  /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
+  void startSketchOperation();
+
 private:
   std::string myAttributeListID;