X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_SketcherReetntrantMgr.cpp;h=95a68cf42f054cc7f186305f12054787aa28e29f;hb=8634847ac05ce637193ec2f5234c3c8996762f94;hp=e063f05daaf6f6b59968fa7e299378be53c68c3e;hpb=834c7f08a1f839bc1cf11d5c206a9d44298bf508;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp index e063f05da..95a68cf42 100755 --- a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -57,9 +58,11 @@ ModuleBase_ModelWidget* PartSet_SketcherReetntrantMgr::internalActiveWidget() co ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); if (anOperation) { ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel(); - ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); - if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector())) - aWidget = myInternalActiveWidget; + 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; } @@ -69,6 +72,27 @@ bool PartSet_SketcherReetntrantMgr::isInternalEditActive() const return myIsInternalEditOperation; } +void PartSet_SketcherReetntrantMgr::updateInternalEditActiveState() +{ + if (myIsInternalEditOperation) { + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (myWorkshop->currentOperation()); + if (aFOperation) { + FeaturePtr aFeature = aFOperation->feature(); + QString anError = myWorkshop->module()->getFeatureError(aFeature); + // stop started internal edit operation as soon as the operation becomes invalid + // it is especially important for the sketch tangent arc feature + if (!anError.isEmpty()) { + aFOperation->setEditOperation(false); + //workshop()->operationMgr()->updateApplyOfOperations(); + beforeStopInternalEdit(); + myIsInternalEditOperation = false; + updateAcceptAllAction(); + } + } + } +} + bool PartSet_SketcherReetntrantMgr::operationCommitted(ModuleBase_Operation* theOperation) { bool aProcessed = false; @@ -86,6 +110,12 @@ void PartSet_SketcherReetntrantMgr::operationStarted(ModuleBase_Operation* theOp if (!isActiveMgr()) return; + if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) { + ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast( + myWorkshop->currentOperation()); + CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch(); + copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch); + } resetFlags(); } @@ -97,8 +127,8 @@ void PartSet_SketcherReetntrantMgr::operationAborted(ModuleBase_Operation* theOp resetFlags(); } -bool PartSet_SketcherReetntrantMgr::processMouseMoved(ModuleBase_IViewWindow* /* theWnd*/, - QMouseEvent* /* theEvent*/) +bool PartSet_SketcherReetntrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd, + QMouseEvent* theEvent) { bool aProcessed = false; if (!isActiveMgr()) @@ -112,48 +142,38 @@ bool PartSet_SketcherReetntrantMgr::processMouseMoved(ModuleBase_IViewWindow* /* if (aLastFeature) { ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget(); ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel(); - bool aWidgetIsFilled = false; - //bool aCanBeActivatedByMove = false; - FeaturePtr aCurrentFeature = anActiveWidget->feature(); + FeaturePtr aCurrentFeature = aFOperation->feature(); bool isLineFeature = false, isArcFeature = false; - if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) - isLineFeature = anActiveWidget->attributeID() == SketchPlugin_Line::START_ID(); - else if (isTangentArc(aFOperation)) - isArcFeature = anActiveWidget->attributeID() == SketchPlugin_Arc::TANGENT_POINT_ID(); - + std::string anAttributeOnStart; + if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) { + anAttributeOnStart = SketchPlugin_Line::START_ID(); + isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart; + } + else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) { + anAttributeOnStart = SketchPlugin_Arc::TANGENT_POINT_ID(); + isArcFeature = anActiveWidget->attributeID() == anAttributeOnStart; + } bool aCanBeActivatedByMove = isLineFeature || isArcFeature; if (aCanBeActivatedByMove) { + myPreviousFeature = aFOperation->feature(); restartOperation(); + myPreviousFeature = FeaturePtr(); anActiveWidget = module()->activeWidget(); aCurrentFeature = anActiveWidget->feature(); aProcessed = true; - if (isLineFeature) { - PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast(anActiveWidget); - if (aPoint2DWdg) { // line, start point should be equal last point of the last feature line - QList aSelection; - aSelection.append(ModuleBase_ViewerPrs(aLastFeature, TopoDS_Shape(), NULL)); - aWidgetIsFilled = aPoint2DWdg->setSelection(aSelection, true); - } - } - else if (isArcFeature) { // arc, start point should be equal last point of the last feature arc - if (aCurrentFeature->getKind() == SketchPlugin_Arc::ID()) { - // get the last point of the previuos arc feature(geom point 2d) - std::shared_ptr aData = aLastFeature->data(); - std::shared_ptr aPointAttr = - std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Arc::END_ID())); - // get point attribute on the current feature - AttributeRefAttrPtr aTangentPointAttr = aCurrentFeature->data()->refattr( - SketchPlugin_Arc::TANGENT_POINT_ID()); - aTangentPointAttr->setAttr(aPointAttr); - aWidgetIsFilled = true; - } + if (anActiveWidget->attributeID() == anAttributeOnStart) { + // it was not deactivated by preselection processing + aPanel->activateNextWidget(anActiveWidget); } + } else { + // processing mouse move in active widget of restarted operation + ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget(); + PartSet_MouseProcessor* aProcessor = dynamic_cast(anActiveWidget); + if (aProcessor) + aProcessor->mouseMoved(theWnd, theEvent); } - if (aWidgetIsFilled) - aPanel->activateNextWidget(anActiveWidget); } } return aProcessed; @@ -184,9 +204,13 @@ bool PartSet_SketcherReetntrantMgr::processMouseReleased(ModuleBase_IViewWindow* // in activate() the value of the point is initialized and it can be displayed // but the default value is [0, 0]. So, we block update viewer contentent until // onMouseRelease happens, which correct the point position - ModuleBase_ModelWidget::blockUpdateViewer(true); + ModuleBase_Tools::blockUpdateViewer(true); + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (myWorkshop->currentOperation()); + myPreviousFeature = aFOperation->feature(); restartOperation(); + myPreviousFeature = FeaturePtr(); aProcessed = true; // fill the first widget by the mouse event point @@ -195,10 +219,10 @@ bool PartSet_SketcherReetntrantMgr::processMouseReleased(ModuleBase_IViewWindow* PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast(module()->activeWidget()); ModuleBase_ModelWidget* aFirstWidget = aPanel->findFirstAcceptingValueWidget(); if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) { - aPoint2DWdg->onMouseRelease(theWnd, theEvent); + aPoint2DWdg->mouseReleased(theWnd, theEvent); } // unblock viewer update - ModuleBase_ModelWidget::blockUpdateViewer(false); + ModuleBase_Tools::blockUpdateViewer(false); } } @@ -241,7 +265,7 @@ void PartSet_SketcherReetntrantMgr::onNoMoreWidgets(const std::string& thePrevio if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) return; - if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) { + if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) { bool isStarted = false; if (!module()->sketchMgr()->sketchSolverError()) { if (myRestartingMode != RM_Forbided) { @@ -288,7 +312,8 @@ void PartSet_SketcherReetntrantMgr::onVertexSelected() ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); std::string anOperationId = anOperation->id().toStdString(); - if (anOperationId == SketchPlugin_Line::ID()/* || isTangentArc(anOperation)*/) { + if (anOperationId == SketchPlugin_Line::ID() || + isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) { /// If last line finished on vertex the lines creation sequence has to be break ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel(); ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); @@ -320,13 +345,18 @@ bool PartSet_SketcherReetntrantMgr::canBeCommittedByPreselection() return !isActiveMgr() || myRestartingMode == RM_None; } +bool PartSet_SketcherReetntrantMgr::isInternalEditStarted() const +{ + return myIsInternalEditOperation; +} + bool PartSet_SketcherReetntrantMgr::isActiveMgr() const { ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation(); bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation); if (!anActive) { - anActive = PartSet_SketcherMgr::isNestedSketchOperation(aCurrentOperation); + anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation); if (anActive) { // the manager is not active when the current operation is a usual Edit ModuleBase_OperationFeature* aFOperation = dynamic_cast (myWorkshop->currentOperation()); @@ -349,13 +379,13 @@ bool PartSet_SketcherReetntrantMgr::startInternalEdit(const std::string& thePrev ModuleBase_OperationFeature* aFOperation = dynamic_cast (myWorkshop->currentOperation()); - if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) { - aFOperation->setEditOperation(false); - workshop()->operationMgr()->updateApplyOfOperations(); - + if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) { + aFOperation->setEditOperation(true/*, false*/); createInternalFeature(); myIsInternalEditOperation = true; + updateAcceptAllAction(); + isDone = true; connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped())); connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped())); @@ -394,7 +424,7 @@ bool PartSet_SketcherReetntrantMgr::startInternalEdit(const std::string& thePrev } // if there is no the next widget to be automatically activated, the Ok button in property // panel should accept the focus(example is parallel constraint on sketch lines) - QToolButton* anOkBtn = aPanel->findChild(PROP_PANEL_OK); + QToolButton* anOkBtn = dynamic_cast(aPanel)->findButton(PROP_PANEL_OK); if (anOkBtn) anOkBtn->setFocus(Qt::TabFocusReason); } @@ -428,14 +458,7 @@ void PartSet_SketcherReetntrantMgr::restartOperation() if (aFOperation) { myNoMoreWidgetsAttribute = ""; myIsFlagsBlocked = true; - FeaturePtr aPrevFeature = aFOperation->feature(); - aFOperation->commit(); module()->launchOperation(aFOperation->id()); - // allow the same attribute values in restarted operation - ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast( - myWorkshop->currentOperation()); - copyReetntrantAttributes(aPrevFeature, aCurrentOperation->feature()); - myIsFlagsBlocked = false; resetFlags(); // we should avoid processing of the signal about no more widgets attributes and @@ -455,13 +478,14 @@ void PartSet_SketcherReetntrantMgr::createInternalFeature() ModuleBase_OperationFeature* aFOperation = dynamic_cast (myWorkshop->currentOperation()); - if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) { + if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) { FeaturePtr anOperationFeature = aFOperation->feature(); CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch(); myInternalFeature = aSketch->addFeature(anOperationFeature->getKind()); - bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature); + bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature, + aSketch, false); XGUI_PropertyPanel* aPropertyPanel = dynamic_cast (aFOperation->propertyPanel()); @@ -506,43 +530,91 @@ void PartSet_SketcherReetntrantMgr::deleteInternalFeature() QObjectPtrList anObjects; anObjects.append(myInternalFeature); workshop()->deleteFeatures(anObjects); + myInternalFeature = FeaturePtr(); } void PartSet_SketcherReetntrantMgr::resetFlags() { if (!myIsFlagsBlocked) { myIsInternalEditOperation = false; + updateAcceptAllAction(); myRestartingMode = RM_None; } } bool PartSet_SketcherReetntrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature, - const FeaturePtr& theNewFeature) + const FeaturePtr& theNewFeature, + const CompositeFeaturePtr& theSketch, + const bool isTemporary) { bool aChanged = false; - std::string aTypeAttributeId; - if (theSourceFeature->getKind() == SketchPlugin_Circle::ID()) { - aTypeAttributeId = SketchPlugin_Circle::CIRCLE_TYPE(); + if (!theSourceFeature.get()) + return aChanged; + + std::string aFeatureKind = theSourceFeature->getKind(); + if (aFeatureKind == SketchPlugin_Line::ID()) { + // Initialize new line with first point equal to end of previous + std::shared_ptr aSFData = theSourceFeature->data(); + std::shared_ptr aSPoint = std::dynamic_pointer_cast( + aSFData->attribute(SketchPlugin_Line::END_ID())); + std::shared_ptr aNFData = theNewFeature->data(); + std::shared_ptr aNPoint = std::dynamic_pointer_cast( + aNFData->attribute(SketchPlugin_Line::START_ID())); + aNPoint->setValue(aSPoint->x(), aSPoint->y()); + PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint); + + aNPoint = std::dynamic_pointer_cast( + aSFData->attribute(SketchPlugin_Line::END_ID())); + aNPoint->setValue(aSPoint->x(), aSPoint->y()); } - if (theSourceFeature->getKind() == SketchPlugin_Arc::ID()) { - aTypeAttributeId = SketchPlugin_Arc::ARC_TYPE(); + else if (aFeatureKind == SketchPlugin_Circle::ID()) { + // set circle type + std::string aTypeAttributeId = SketchPlugin_Circle::CIRCLE_TYPE(); + AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId); + AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId); + aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value()); + //ModuleBase_Tools::flushUpdated(theNewFeature); + aChanged = true; } - if (!aTypeAttributeId.empty()) { + else if (aFeatureKind == SketchPlugin_Arc::ID()) { + // set arc type + std::string aTypeAttributeId = SketchPlugin_Arc::ARC_TYPE(); AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId); AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId); aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value()); - ModuleBase_ModelWidget::updateObject(theNewFeature); + + // if the arc is tangent, set coincidence to end point of the previous arc + std::string anArcType = aSourceFeatureTypeAttr->value(); + if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) { + // get the last point of the previuos arc feature(geom point 2d) + std::shared_ptr aSData = theSourceFeature->data(); + std::shared_ptr aSPointAttr = + std::dynamic_pointer_cast( + aSData->attribute(SketchPlugin_Arc::END_ID())); + // get point attribute on the current feature + AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr( + SketchPlugin_Arc::TANGENT_POINT_ID()); + aTangentPointAttr->setAttr(aSPointAttr); + + std::shared_ptr aNPointAttr = + std::dynamic_pointer_cast( + theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID())); + aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y()); + + } + //ModuleBase_Tools::flushUpdated(theNewFeature); aChanged = true; } return aChanged; } -bool PartSet_SketcherReetntrantMgr::isTangentArc(ModuleBase_Operation* theOperation) +bool PartSet_SketcherReetntrantMgr::isTangentArc(ModuleBase_Operation* theOperation, + const CompositeFeaturePtr& /*theSketch*/) const { bool aTangentArc = false; ModuleBase_OperationFeature* aFOperation = dynamic_cast (theOperation); - if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) { + if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) { FeaturePtr aFeature = aFOperation->feature(); if (aFeature.get() && aFeature->getKind() == SketchPlugin_Arc::ID()) { AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_Arc::ARC_TYPE()); @@ -553,6 +625,13 @@ bool PartSet_SketcherReetntrantMgr::isTangentArc(ModuleBase_Operation* theOperat return aTangentArc; } +void PartSet_SketcherReetntrantMgr::updateAcceptAllAction() +{ + CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch(); + if (aSketch.get()) + workshop()->errorMgr()->updateAcceptAllAction(aSketch); +} + XGUI_Workshop* PartSet_SketcherReetntrantMgr::workshop() const { XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop);