X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_SketcherReentrantMgr.cpp;h=ea08becbc2b3469d2d0ea38ea35e296136e7e14d;hb=1fd15bed1c62f994a3438bc4a12f44d0361f98c9;hp=0e4aebf79659148efb77fa162fe1e4e4f941771d;hpb=b059beaa04c31859789fe2f56e70ebd07e4e829f;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.cpp b/src/PartSet/PartSet_SketcherReentrantMgr.cpp index 0e4aebf79..ea08becbc 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReentrantMgr.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,13 +12,13 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "PartSet_SketcherReentrantMgr.h" +#include "PartSet_ExternalObjectsMgr.h" #include "PartSet_Module.h" #include "PartSet_SketcherMgr.h" #include "PartSet_WidgetPoint2d.h" @@ -31,6 +31,9 @@ #include "GeomDataAPI_Point2D.h" +#include "GeomAPI_Lin2d.h" +#include "GeomAPI_Dir2d.h" + #include #include #include @@ -43,7 +46,6 @@ #include #include "ModuleBase_ToolBox.h" #include "ModuleBase_ISelection.h" -#include "ModuleBase_ISelectionActivate.h" #include #include @@ -52,6 +54,8 @@ #include #include #include +#include +#include #include #include @@ -70,8 +74,9 @@ PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* myRestartingMode(RM_None), myIsFlagsBlocked(false), myIsInternalEditOperation(false), - myInternalActiveWidget(0), - myNoMoreWidgetsAttribute("") + myNoMoreWidgetsAttribute(""), + myIsAutoConstraints(true), + myLastAutoConstraint(0) { } @@ -79,24 +84,6 @@ PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr() { } -ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const -{ - ModuleBase_ModelWidget* aWidget = 0; - if (!isActiveMgr()) - return aWidget; - - ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); - if (anOperation) { - ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel(); - if (aPanel) { // check for case when the operation is started but property panel is not filled - ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); - if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector())) - aWidget = myInternalActiveWidget; - } - } - return aWidget; -} - bool PartSet_SketcherReentrantMgr::isInternalEditActive() const { return myIsInternalEditOperation; @@ -202,8 +189,8 @@ bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* the } } else { // processing mouse move in active widget of restarted operation - ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget(); - PartSet_MouseProcessor* aProcessor = dynamic_cast(anActiveWidget); + ModuleBase_ModelWidget* anActiveWdg = module()->activeWidget(); + PartSet_MouseProcessor* aProcessor = dynamic_cast(anActiveWdg); if (aProcessor) aProcessor->mouseMoved(theWnd, theEvent); } @@ -254,6 +241,7 @@ bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, module()->sketchMgr()->activeSketch()); + FeaturePtr anExternalCreatedFeature; if (!aPreSelected.empty()) { ModuleBase_ViewerPrsPtr aValue = aPreSelected.first(); module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute); @@ -262,10 +250,23 @@ bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* if (aPointWidget) { GeomShapePtr aShape; aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape); + ObjectPtr anExternalObject = + aPointWidget->getExternalObjectMgr()->getExternalObjectValidated(); + // if external object is during reentrant operation and is used as a parameter of feature + // it should be removed after the operation is restarted. (Circle feature, Projection) + if (anExternalObject.get()) + anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject); } } restartOperation(); + // remove created external feature + if (anExternalCreatedFeature.get()) { + QObjectPtrList anObjects; + anObjects.append(anExternalCreatedFeature); + workshop()->deleteFeatures(anObjects); + } + myClickedSketchPoint = std::shared_ptr(); mySelectedObject = ObjectPtr(); mySelectedAttribute = AttributePtr(); @@ -333,9 +334,10 @@ void PartSet_SketcherReentrantMgr::setReentrantPreSelection( // ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget(); // ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel(); // if (aFirstWidget != aPanel->activeWidget()) { -// ModuleBase_WidgetSelector* aWSelector = dynamic_cast(aFirstWidget); +// ModuleBase_WidgetSelector* aWSelector = dynamic_cast +// (aFirstWidget); // if (aWSelector) { -// myWorkshop->selectionActivate()->activateSelectionAndFilters(aWSelector); +// myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector); // } // } //} @@ -360,19 +362,32 @@ void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviou ModuleBase_OperationFeature* aFOperation = dynamic_cast (myWorkshop->currentOperation()); + if (module()->sketchMgr()->isDragModeCreation()) { + if (aFOperation && myIsAutoConstraints) + addConstraints(aFOperation->feature()); + return; + } if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) return; if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) { - bool isStarted = false; - if (!module()->sketchMgr()->sketchSolverError()) { - if (myRestartingMode != RM_Forbided) { - myRestartingMode = RM_LastFeatureUsed; - isStarted = startInternalEdit(thePreviousAttributeID); + if (aFOperation->isNeedToBeAborted()) { + aFOperation->abort(); + } + else { + bool isStarted = false; + if (!module()->sketchMgr()->sketchSolverError()) { + if (myRestartingMode != RM_Forbided) { + myRestartingMode = RM_LastFeatureUsed; + isStarted = startInternalEdit(thePreviousAttributeID); + } + } + if (!isStarted) { + if (myIsAutoConstraints) + addConstraints(aFOperation->feature()); + aFOperation->commit(); } } - if (!isStarted) - aFOperation->commit(); } } @@ -397,7 +412,9 @@ bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAt if (!isSketchSolverError) { myRestartingMode = RM_EmptyFeatureUsed; - isDone = startInternalEdit(thePreviousAttributeID); + // It seems that the call is obsolete for Enter key processing + // It prevent finalysing of the current operation by Enter key + //isDone = startInternalEdit(thePreviousAttributeID); } return isDone; @@ -432,10 +449,7 @@ void PartSet_SketcherReentrantMgr::onVertexSelected() void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel() { - if (isInternalEditActive()) { - ModuleBase_OperationFeature* aFOperation = dynamic_cast - (myWorkshop->currentOperation()); ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender(); if (!aWidget->isModifiedInEdit().empty()) restartOperation(); @@ -493,6 +507,9 @@ bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePrevi // returning to the neutral point of the Sketcher or start internal edit workshop()->selector()->clearSelection(); + if (myIsAutoConstraints) + addConstraints(aFOperation->feature()); + aFOperation->setEditOperation(true/*, false*/); createInternalFeature(); @@ -515,9 +532,9 @@ bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePrevi QList aWidgets = aPanel->modelWidgets(); for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) { if (aWidgets[i]->attributeID() == thePreviousAttributeID) { - /// workaround for the same attributes used in different stacked widgets(attribute types) - if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i])) - continue; + // workaround for the same attributes used in different stacked widgets(attribute types) + if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i])) + continue; aPreviousAttributeWidget = aWidgets[i]; } } @@ -649,7 +666,7 @@ void PartSet_SketcherReentrantMgr::createInternalFeature() ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget (aWidgets); if (aFirstWidget) - myInternalActiveWidget = aFirstWidget; + setInternalActiveWidget(aFirstWidget); } } @@ -659,13 +676,7 @@ void PartSet_SketcherReentrantMgr::deleteInternalFeature() std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: " << myInternalFeature->data()->name() << std::endl; #endif - if (myInternalActiveWidget) { - ModuleBase_WidgetSelector* aWSelector = - dynamic_cast(myInternalActiveWidget); - if (aWSelector) - myWorkshop->selectionActivate()->activateSelectionAndFilters(aWSelector); - myInternalActiveWidget = 0; - } + setInternalActiveWidget(0); delete myInternalWidget; myInternalWidget = 0; @@ -814,3 +825,69 @@ PartSet_Module* PartSet_SketcherReentrantMgr::module() const { return dynamic_cast(myWorkshop->module()); } + +void PartSet_SketcherReentrantMgr::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget) +{ + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (myWorkshop->currentOperation()); + if (aFOperation) + { + XGUI_PropertyPanel* aPropertyPanel = dynamic_cast + (aFOperation->propertyPanel()); + if (aPropertyPanel) + aPropertyPanel->setInternalActiveWidget(theWidget); + } +} + +void PartSet_SketcherReentrantMgr::onAutoConstraints(bool isOn) +{ + myIsAutoConstraints = isOn; +} + +void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature) +{ + if (theFeature->getKind() != SketchPlugin_Line::ID()) + return; + + static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0)); + static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1)); + + std::shared_ptr aData = theFeature->data(); + std::shared_ptr aPoint1 = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aPoint2 = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::END_ID())); + if (aPoint1.get() && aPoint2.get()) { + GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPoint1->pnt(), aPoint2->pnt())); + GeomDir2dPtr aDir = aLine->direction(); + double aHorAngle = fabs(myHorDir->angle(aDir)); + double aVertAngle = fabs(myVertDir->angle(aDir)); + if (aHorAngle > M_PI/2.) + aHorAngle = M_PI - aHorAngle; + if (aVertAngle > M_PI/2.) + aVertAngle = M_PI - aVertAngle; + + double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance"); + CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch(); + FeaturePtr aFeature; + if (aHorAngle < aTolerance) { + // Add horizontal constraint + aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID()); + } + else if (aVertAngle < aTolerance) { + // Add vertical constraint + aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID()); + } + if (aFeature.get()) { + aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject( + theFeature->firstResult()); + myLastAutoConstraint = aFeature.get(); + } + } +} + + +bool PartSet_SketcherReentrantMgr::isLastAutoConstraint(const ObjectPtr& theObj) const +{ + return theObj.get() == myLastAutoConstraint; +}