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();
179 if (anActiveWidget && anActiveWidget->attributeID() == anAttributeOnStart) {
180 // it was not deactivated by preselection processing
181 aPanel->activateNextWidget(anActiveWidget);
184 // processing mouse move in active widget of restarted operation
185 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
186 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
188 aProcessor->mouseMoved(theWnd, theEvent);
195 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
196 QMouseEvent* /* theEvent*/)
198 return isActiveMgr() && myIsInternalEditOperation;
201 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
202 QMouseEvent* theEvent)
204 bool aProcessed = false;
208 if (myIsInternalEditOperation) {
209 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
210 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
212 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
213 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
215 // block of viewer update
216 // we need to block update content of the viewer because of Sketch Point feature
217 // in activate() the value of the point is initialized and it can be displayed
218 // but the default value is [0, 0]. So, we block update viewer contentent until
219 // onMouseRelease happens, which correct the point position
220 ModuleBase_Tools::blockUpdateViewer(true);
222 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
223 (myWorkshop->currentOperation());
224 myPreviousFeature = aFOperation->feature();
226 /// selection should be obtained from workshop before ask if the operation can be started as
227 /// the canStartOperation method performs commit/abort of previous operation.
228 /// Sometimes commit/abort
229 /// may cause selection clear(Sketch operation) as a result
230 /// it will be lost and is not used for preselection.
231 ModuleBase_ISelection* aSelection = myWorkshop->selection();
232 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
233 aSelection->getSelected(ModuleBase_ISelection::AllControls);
235 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
236 module()->sketchMgr()->activeSketch());
237 if (!aPreSelected.empty()) {
238 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
239 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
241 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
244 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
249 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
250 mySelectedObject = ObjectPtr();
251 mySelectedAttribute = AttributePtr();
253 myPreviousFeature = FeaturePtr();
256 // fill the first widget by the mouse event point
257 // if the active widget is not the first, it means that the restarted operation is filled by
258 // the current preselection.
259 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
260 module()->activeWidget());
261 //PartSet_WidgetPoint2D* aPoint2DWdg =
262 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
263 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
264 aPanel->findFirstAcceptingValueWidget());
265 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
266 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
267 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
268 if (!aPreSelected.empty())
269 aSelectedPrs = aPreSelected.front();
270 if (aSelectedPrs.get() && aSelectedPrs->object().get()
271 && !aSelectedPrs->object()->data()->isValid()) {
272 // the selected object was removed diring restart, e.g. presentable macro feature
273 // there are created objects to replace the object depending on created feature kind
274 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
276 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
277 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
278 //if (!aPreSelected.empty())
279 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
281 // unblock viewer update
282 ModuleBase_Tools::blockUpdateViewer(false);
288 //******************************************************
289 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
290 const std::shared_ptr<Events_Message>& theMessage)
292 ReentrantMessagePtr aReentrantMessage =
293 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
294 if (!aReentrantMessage.get())
297 // if feature has already filled the selected object, we should not overwrite it
298 if (!aReentrantMessage->selectedObject().get())
299 aReentrantMessage->setSelectedObject(mySelectedObject);
301 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
302 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
305 void PartSet_SketcherReentrantMgr::onWidgetActivated()
309 if (!myIsInternalEditOperation)
312 PartSet_Module* aModule = module();
313 ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
314 ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
315 if (aFirstWidget != aPanel->activeWidget()) {
316 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
318 aWSelector->activateSelectionAndFilters(true);
322 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
325 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
331 // we should avoid processing of the signal about no more widgets attributes and
332 // do this after the restart operaion is finished if it was called
333 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
334 // if it should be called after restart
335 if (myIsFlagsBlocked) {
336 myNoMoreWidgetsAttribute = thePreviousAttributeID;
340 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
341 (myWorkshop->currentOperation());
342 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
345 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
346 bool isStarted = false;
347 if (!module()->sketchMgr()->sketchSolverError()) {
348 if (myRestartingMode != RM_Forbided) {
349 myRestartingMode = RM_LastFeatureUsed;
350 isStarted = startInternalEdit(thePreviousAttributeID);
354 aFOperation->commit();
358 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
365 // empty previous attribute means that the Apply/Ok button has focus and the enter
366 // should not lead to start edition mode of the previous operation
367 if (thePreviousAttributeID.empty())
370 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
371 (myWorkshop->currentOperation());
372 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
375 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
377 if (!isSketchSolverError) {
378 myRestartingMode = RM_EmptyFeatureUsed;
379 isDone = startInternalEdit(thePreviousAttributeID);
385 void PartSet_SketcherReentrantMgr::onVertexSelected()
390 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
391 std::string anOperationId = anOperation->id().toStdString();
392 if (anOperationId == SketchPlugin_Line::ID() ||
393 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
394 /// If last line finished on vertex the lines creation sequence has to be break
395 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
396 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
397 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
398 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
399 bool aFoundWidget = false;
400 bool aFoundObligatory = false;
401 for (; anIt != aLast && !aFoundObligatory; anIt++) {
403 aFoundWidget = *anIt == anActiveWidget;
405 aFoundObligatory = (*anIt)->isObligatory();
407 if (!aFoundObligatory)
408 myRestartingMode = RM_Forbided;
412 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
415 if (isInternalEditActive()) {
416 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
417 (myWorkshop->currentOperation());
418 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
419 if (!aWidget->isModifiedInEdit().empty())
424 void PartSet_SketcherReentrantMgr::onBeforeStopped()
426 if (!isActiveMgr() || !myIsInternalEditOperation)
429 beforeStopInternalEdit();
432 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
434 return !isActiveMgr() || myRestartingMode == RM_None;
437 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
439 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
441 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
443 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
444 if (anActive) { // the manager is not active when the current operation is a usual Edit
445 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
446 (myWorkshop->currentOperation());
447 if (aFOperation->isEditOperation())
448 anActive = myIsInternalEditOperation;
454 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
457 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
461 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
462 /// event comes two times, so we should not start another internal edit operation
463 /// the Apply button becomes disabled becase the second additional internal feature is created
464 if (myIsInternalEditOperation)
467 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
468 (myWorkshop->currentOperation());
470 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
471 aFOperation->setEditOperation(true/*, false*/);
472 createInternalFeature();
474 myIsInternalEditOperation = true;
475 updateAcceptAllAction();
478 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
479 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
481 // activate selection filters of the first widget in the viewer
484 // activate the last active widget in the Property Panel
485 if (!thePreviousAttributeID.empty()) {
486 ModuleBase_Operation* anEditOperation = module()->currentOperation();
487 if (anEditOperation) {
488 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
489 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
490 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
491 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
492 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
493 /// workaround for the same attributes used in different stacked widgets(attribute types)
494 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
496 aPreviousAttributeWidget = aWidgets[i];
499 // If the current widget is a selector, do nothing, it processes the mouse press
500 if (aPreviousAttributeWidget) {
501 if (!aPreviousAttributeWidget->isViewerSelector()) {
502 aPreviousAttributeWidget->focusTo();
503 aPreviousAttributeWidget->emitFocusInWidget();
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());