From: nds Date: Mon, 21 Mar 2016 10:32:07 +0000 (+0300) Subject: Issue #1343 Improvement of Extrusion and Revolution operations: selection processing... X-Git-Tag: V_2.3.0~336 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2a180ef10197cde8d43ae2d08cc9e1e40bdbc1e5;p=modules%2Fshaper.git Issue #1343 Improvement of Extrusion and Revolution operations: selection processing for sketch creation or extrusion filling. --- diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index b6425362b..09462cf8e 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -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"> diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 874d917b1..972a0e7a8 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -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 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::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& 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(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(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 diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index e14352a0c..a03e71021 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -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& theValues); private: std::string myAttributeListID; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 81ba4a898..cc56f1abd 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -320,6 +320,32 @@ bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrs& t return fillSketchPlaneBySelection(feature(), thePrs); } +#include +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(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 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) { diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index ff6689d1c..956b06ee0 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -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);