1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_SketcherReentrantMgr.h"
4 #include "PartSet_Module.h"
5 #include "PartSet_SketcherMgr.h"
6 #include "PartSet_WidgetPoint2d.h"
8 #include "ModelAPI_Session.h"
9 #include "ModelAPI_AttributeString.h"
10 #include "ModelAPI_AttributeRefAttr.h"
11 #include "ModelAPI_AttributeReference.h"
12 #include "ModelAPI_EventReentrantMessage.h"
14 #include "GeomDataAPI_Point2D.h"
16 #include <ModuleBase_IPropertyPanel.h>
17 #include <ModuleBase_OperationFeature.h>
18 #include <ModuleBase_ModelWidget.h>
19 #include <ModuleBase_ViewerPrs.h>
20 #include <ModuleBase_WidgetSelector.h>
21 #include <ModuleBase_PageWidget.h>
22 #include <ModuleBase_PageBase.h>
23 #include <ModuleBase_WidgetFactory.h>
24 #include <ModuleBase_OperationDescription.h>
25 #include "ModuleBase_ToolBox.h"
26 #include "ModuleBase_ISelection.h"
28 #include <SketchPlugin_Feature.h>
29 #include <SketchPlugin_Line.h>
30 #include <SketchPlugin_MacroArc.h>
31 #include <SketchPlugin_MacroCircle.h>
32 #include <SketchPlugin_Point.h>
33 #include <SketchPlugin_Trim.h>
34 #include <SketchPlugin_Split.h>
36 #include <XGUI_Workshop.h>
37 #include <XGUI_ModuleConnector.h>
38 #include <XGUI_OperationMgr.h>
39 #include <XGUI_PropertyPanel.h>
40 #include <XGUI_ErrorMgr.h>
41 #include <XGUI_SelectionMgr.h>
43 #include <QToolButton>
45 //#define DEBUG_RESTART
47 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
48 : QObject(theWorkshop),
49 myWorkshop(theWorkshop),
50 myRestartingMode(RM_None),
51 myIsFlagsBlocked(false),
52 myIsInternalEditOperation(false),
53 myInternalActiveWidget(0),
54 myNoMoreWidgetsAttribute("")
58 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
62 ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
64 ModuleBase_ModelWidget* aWidget = 0;
68 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
70 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
71 if (aPanel) { // check for case when the operation is started but property panel is not filled
72 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
73 if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
74 aWidget = myInternalActiveWidget;
80 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
82 return myIsInternalEditOperation;
85 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
87 if (myIsInternalEditOperation) {
88 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
89 (myWorkshop->currentOperation());
91 FeaturePtr aFeature = aFOperation->feature();
92 QString anError = myWorkshop->module()->getFeatureError(aFeature);
93 // stop started internal edit operation as soon as the operation becomes invalid
94 // it is especially important for the sketch tangent arc feature
95 if (!anError.isEmpty()) {
96 aFOperation->setEditOperation(false);
97 //workshop()->operationMgr()->updateApplyOfOperations();
98 myIsInternalEditOperation = false;
99 updateAcceptAllAction();
105 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
107 bool aProcessed = false;
111 aProcessed = myIsInternalEditOperation;
117 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
122 //if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
123 //ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
124 // myWorkshop->currentOperation());
125 //CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
126 //if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
127 //copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
132 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
140 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
141 QMouseEvent* theEvent)
143 bool aProcessed = false;
147 if (myIsInternalEditOperation) {
148 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
149 (myWorkshop->currentOperation());
150 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
153 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
154 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
156 FeaturePtr aCurrentFeature = aFOperation->feature();
157 bool isLineFeature = false, isReentrantArcFeature = false;
158 std::string anAttributeOnStart;
159 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
160 anAttributeOnStart = SketchPlugin_Line::START_ID();
161 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
163 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
164 isReentrantArcFeature = true;
166 bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature;
167 if (aCanBeActivatedByMove) {
168 /// before restarting of operation we need to clear selection, as it may take part in
169 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
170 /// by mouse release when the operation was restarted.
171 workshop()->selector()->clearSelection();
173 myPreviousFeature = aFOperation->feature();
175 myPreviousFeature = FeaturePtr();
177 anActiveWidget = module()->activeWidget();
178 aCurrentFeature = anActiveWidget->feature();
180 if (anActiveWidget->attributeID() == anAttributeOnStart) {
181 // it was not deactivated by preselection processing
182 aPanel->activateNextWidget(anActiveWidget);
185 // processing mouse move in active widget of restarted operation
186 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
187 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
189 aProcessor->mouseMoved(theWnd, theEvent);
196 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
197 QMouseEvent* /* theEvent*/)
199 return isActiveMgr() && myIsInternalEditOperation;
202 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
203 QMouseEvent* theEvent)
205 bool aProcessed = false;
209 if (myIsInternalEditOperation) {
210 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
211 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
213 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
214 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
216 // block of viewer update
217 // we need to block update content of the viewer because of Sketch Point feature
218 // in activate() the value of the point is initialized and it can be displayed
219 // but the default value is [0, 0]. So, we block update viewer contentent until
220 // onMouseRelease happens, which correct the point position
221 ModuleBase_Tools::blockUpdateViewer(true);
223 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
224 (myWorkshop->currentOperation());
225 myPreviousFeature = aFOperation->feature();
227 /// selection should be obtained from workshop before ask if the operation can be started as
228 /// the canStartOperation method performs commit/abort of previous operation.
229 /// Sometimes commit/abort
230 /// may cause selection clear(Sketch operation) as a result
231 /// it will be lost and is not used for preselection.
232 ModuleBase_ISelection* aSelection = myWorkshop->selection();
233 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
234 aSelection->getSelected(ModuleBase_ISelection::AllControls);
236 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
237 module()->sketchMgr()->activeSketch());
238 if (!aPreSelected.empty()) {
239 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
240 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
242 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
245 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
250 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
251 mySelectedObject = ObjectPtr();
252 mySelectedAttribute = AttributePtr();
254 myPreviousFeature = FeaturePtr();
257 // fill the first widget by the mouse event point
258 // if the active widget is not the first, it means that the restarted operation is filled by
259 // the current preselection.
260 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
261 module()->activeWidget());
262 //PartSet_WidgetPoint2D* aPoint2DWdg =
263 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
264 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
265 aPanel->findFirstAcceptingValueWidget());
266 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
267 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
268 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
269 if (!aPreSelected.empty())
270 aSelectedPrs = aPreSelected.front();
271 if (aSelectedPrs.get() && aSelectedPrs->object().get()
272 && !aSelectedPrs->object()->data()->isValid()) {
273 // the selected object was removed diring restart, e.g. presentable macro feature
274 // there are created objects to replace the object depending on created feature kind
275 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
277 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
278 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
279 //if (!aPreSelected.empty())
280 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
282 // unblock viewer update
283 ModuleBase_Tools::blockUpdateViewer(false);
289 //******************************************************
290 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
291 const std::shared_ptr<Events_Message>& theMessage)
293 ReentrantMessagePtr aReentrantMessage =
294 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
295 if (!aReentrantMessage.get())
298 // if feature has already filled the selected object, we should not overwrite it
299 if (!aReentrantMessage->selectedObject().get())
300 aReentrantMessage->setSelectedObject(mySelectedObject);
302 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
303 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
306 void PartSet_SketcherReentrantMgr::onWidgetActivated()
310 if (!myIsInternalEditOperation)
313 PartSet_Module* aModule = module();
314 ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
315 ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
316 if (aFirstWidget != aPanel->activeWidget()) {
317 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
319 aWSelector->activateSelectionAndFilters(true);
323 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
326 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
332 // we should avoid processing of the signal about no more widgets attributes and
333 // do this after the restart operaion is finished if it was called
334 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
335 // if it should be called after restart
336 if (myIsFlagsBlocked) {
337 myNoMoreWidgetsAttribute = thePreviousAttributeID;
341 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
342 (myWorkshop->currentOperation());
343 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
346 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
347 bool isStarted = false;
348 if (!module()->sketchMgr()->sketchSolverError()) {
349 if (myRestartingMode != RM_Forbided) {
350 myRestartingMode = RM_LastFeatureUsed;
351 isStarted = startInternalEdit(thePreviousAttributeID);
355 aFOperation->commit();
359 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
366 // empty previous attribute means that the Apply/Ok button has focus and the enter
367 // should not lead to start edition mode of the previous operation
368 if (thePreviousAttributeID.empty())
371 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
372 (myWorkshop->currentOperation());
373 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
376 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
378 if (!isSketchSolverError) {
379 myRestartingMode = RM_EmptyFeatureUsed;
380 isDone = startInternalEdit(thePreviousAttributeID);
386 void PartSet_SketcherReentrantMgr::onVertexSelected()
391 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
392 std::string anOperationId = anOperation->id().toStdString();
393 if (anOperationId == SketchPlugin_Line::ID() ||
394 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
395 /// If last line finished on vertex the lines creation sequence has to be break
396 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
397 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
398 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
399 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
400 bool aFoundWidget = false;
401 bool aFoundObligatory = false;
402 for (; anIt != aLast && !aFoundObligatory; anIt++) {
404 aFoundWidget = *anIt == anActiveWidget;
406 aFoundObligatory = (*anIt)->isObligatory();
408 if (!aFoundObligatory)
409 myRestartingMode = RM_Forbided;
413 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
416 if (isInternalEditActive()) {
417 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
418 (myWorkshop->currentOperation());
419 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
420 if (!aWidget->isModifiedInEdit().empty())
425 void PartSet_SketcherReentrantMgr::onBeforeStopped()
427 if (!isActiveMgr() || !myIsInternalEditOperation)
430 beforeStopInternalEdit();
433 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
435 return !isActiveMgr() || myRestartingMode == RM_None;
438 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
440 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
442 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
444 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
445 if (anActive) { // the manager is not active when the current operation is a usual Edit
446 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
447 (myWorkshop->currentOperation());
448 if (aFOperation->isEditOperation())
449 anActive = myIsInternalEditOperation;
455 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
458 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
462 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
463 /// event comes two times, so we should not start another internal edit operation
464 /// the Apply button becomes disabled becase the second additional internal feature is created
465 if (myIsInternalEditOperation)
468 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
469 (myWorkshop->currentOperation());
471 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
472 aFOperation->setEditOperation(true/*, false*/);
473 createInternalFeature();
475 myIsInternalEditOperation = true;
476 updateAcceptAllAction();
479 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
480 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
482 // activate selection filters of the first widget in the viewer
485 // activate the last active widget in the Property Panel
486 if (!thePreviousAttributeID.empty()) {
487 ModuleBase_Operation* anEditOperation = module()->currentOperation();
488 if (anEditOperation) {
489 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
490 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
491 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
492 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
493 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
494 /// workaround for the same attributes used in different stacked widgets(attribute types)
495 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
497 aPreviousAttributeWidget = aWidgets[i];
500 // If the current widget is a selector, do nothing, it processes the mouse press
501 if (aPreviousAttributeWidget) {
502 if (!aPreviousAttributeWidget->isViewerSelector()) {
503 aPreviousAttributeWidget->focusTo();
504 aPreviousAttributeWidget->selectContent();
507 // in case of shape multi selector, the widget does not lose focus by filling
508 // like it is in shape selector. So, if enter is pressed, the multi shape selector
509 // control should be deactivated. The focus is moved to Apply button and there
510 // should not be active control visualized in property panel
511 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
512 aPanel->activateWidget(NULL, false);
514 // if there is no the next widget to be automatically activated,
515 // the Ok button in property
516 // panel should accept the focus(example is parallel constraint on sketch lines)
517 QToolButton* anOkBtn =
518 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
520 anOkBtn->setFocus(Qt::TabFocusReason);
527 module()->sketchMgr()->clearClickedFlags();
532 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
534 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
535 (myWorkshop->currentOperation());
537 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
538 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
541 deleteInternalFeature();
544 void PartSet_SketcherReentrantMgr::restartOperation()
547 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
550 if (myIsInternalEditOperation) {
551 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
552 myWorkshop->currentOperation());
554 ModuleBase_ISelection* aSelection = myWorkshop->selection();
555 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
556 aSelection->getSelected(ModuleBase_ISelection::AllControls);
558 if (myInternalFeature.get())
559 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
560 module()->sketchMgr()->activeSketch());
562 myNoMoreWidgetsAttribute = "";
563 myIsFlagsBlocked = true;
564 /// launch has 'false' parameter to do not start new operation if the previous operation
565 /// is not committed. It is important for Line Sketch feature as it uses the previous
566 /// created feature parameter(to build coincidence), but by abort the previous is removed
567 module()->launchOperation(aFOperation->id(), true);
568 myIsFlagsBlocked = false;
571 // we should avoid processing of the signal about no more widgets attributes and
572 // do this after the restart operaion is finished if it was called
573 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
574 // if it should be called after restart
575 if (!myNoMoreWidgetsAttribute.empty()) {
576 onNoMoreWidgets(myNoMoreWidgetsAttribute);
577 myNoMoreWidgetsAttribute = "";
583 void PartSet_SketcherReentrantMgr::createInternalFeature()
585 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
586 (myWorkshop->currentOperation());
588 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
589 FeaturePtr anOperationFeature = aFOperation->feature();
591 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
592 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
595 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
596 << myInternalFeature->data()->name() << std::endl;
599 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
601 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
602 (aFOperation->propertyPanel());
604 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
605 myInternalWidget->setVisible(false);
607 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
609 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
610 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
612 aFactory.createWidget(anInternalPage);
613 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
615 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
616 bool isStoreValue = !aFOperation->isEditOperation() &&
617 !aWidget->getDefaultValue().empty() &&
618 !aWidget->isComputedDefault();
619 aWidget->setFeature(myInternalFeature, isStoreValue);
620 if (!isStoreValue && isFeatureChanged)
621 aWidget->restoreValue();
624 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
627 myInternalActiveWidget = aFirstWidget;
631 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
634 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
635 << myInternalFeature->data()->name() << std::endl;
637 if (myInternalActiveWidget) {
638 ModuleBase_WidgetSelector* aWSelector =
639 dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
641 aWSelector->activateSelectionAndFilters(false);
642 myInternalActiveWidget = 0;
644 delete myInternalWidget;
645 myInternalWidget = 0;
647 QObjectPtrList anObjects;
648 anObjects.append(myInternalFeature);
649 workshop()->deleteFeatures(anObjects);
650 myInternalFeature = FeaturePtr();
653 void PartSet_SketcherReentrantMgr::resetFlags()
655 if (!myIsFlagsBlocked) {
656 myIsInternalEditOperation = false;
657 updateAcceptAllAction();
658 myRestartingMode = RM_None;
659 myReentrantMessage = std::shared_ptr<Events_Message>();
663 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
664 const FeaturePtr& theNewFeature,
665 const CompositeFeaturePtr& theSketch,
666 const bool /*isTemporary*/)
668 bool aChanged = false;
669 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
670 !theSourceFeature->data()->isValid())
674 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
675 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
679 std::string aFeatureKind = theSourceFeature->getKind();
680 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
681 // Initialize new line with first point equal to end of previous
682 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
683 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
684 aSFData->attribute(SketchPlugin_Line::END_ID()));
685 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
686 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
687 aNFData->attribute(SketchPlugin_Line::START_ID()));
688 aNPoint->setValue(aSPoint->x(), aSPoint->y());
689 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
691 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
692 aSFData->attribute(SketchPlugin_Line::END_ID()));
693 aNPoint->setValue(aSPoint->x(), aSPoint->y());
695 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
697 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
698 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
699 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
700 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
701 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
702 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
705 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
707 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
708 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
709 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
710 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
711 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
712 //// if the arc is tangent, set coincidence to end point of the previous arc
713 //std::string anArcType = aSourceFeatureTypeAttr->value();
714 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
715 // // get the last point of the previuos arc feature(geom point 2d)
716 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
717 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
718 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
719 // aSData->attribute(SketchPlugin_Arc::END_ID()));
720 // // get point attribute on the current feature
721 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
722 // SketchPlugin_Arc::TANGENT_POINT_ID());
723 // aTangentPointAttr->setAttr(aSPointAttr);
725 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
726 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
727 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
728 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
731 //ModuleBase_Tools::flushUpdated(theNewFeature);
734 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
735 aFeatureKind == SketchPlugin_Split::ID()) {
736 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
737 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
738 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
739 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
740 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
741 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
742 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
743 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
744 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
745 theNewFeature->data()->attribute(aPreviewObjectAttribute));
746 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
747 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
748 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
749 theSourceFeature->data()->attribute(aPreviewPointAttribute));
750 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
751 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
752 theNewFeature->data()->attribute(aPreviewPointAttribute));
753 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
758 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
759 const CompositeFeaturePtr& /*theSketch*/) const
761 bool aTangentArc = false;
762 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
764 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
765 FeaturePtr aFeature = aFOperation->feature();
766 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
767 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
768 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
769 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
775 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
777 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
779 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
782 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
784 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
785 return aConnector->workshop();
788 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
790 return dynamic_cast<PartSet_Module*>(myWorkshop->module());