From 67d2124f9ed5e641e55cd4f625e61896fdb353bb Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 18 Mar 2016 11:59:47 +0300 Subject: [PATCH] Issue #1343 Improvement of Extrusion and Revolution operations: selection processing to continue extrusion or start sketch. --- src/FeaturesPlugin/extrusion_widget.xml | 1 + src/ModuleBase/ModuleBase_WidgetSelector.h | 15 +++-- src/PartSet/PartSet_WidgetSketchCreator.cpp | 67 ++++++++++++++++++--- src/PartSet/PartSet_WidgetSketchCreator.h | 16 +++++ 4 files changed, 85 insertions(+), 14 deletions(-) diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index ac410cf69..b6425362b 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -2,6 +2,7 @@ getAttributeSelection() const; + // NDS: has body is temporary + virtual QList 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(); diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 22e839ce5..71069fe36 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -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 aSelected = getFilteredSelected(); + + if (aSelected.size() == 1) { // plane or planar face of not sketch object + startSketchOperation(); + } + else if (aSelected.size() > 1) { + QList::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(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(myModule->workshop()); + /*XGUI_ModuleConnector* aConnector = dynamic_cast(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(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 { diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index f52a0f1fa..7349d1615 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -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; -- 2.39.2