1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_SketcherReentrantMgr.h"
22 #include "PartSet_ExternalObjectsMgr.h"
23 #include "PartSet_Module.h"
24 #include "PartSet_SketcherMgr.h"
25 #include "PartSet_WidgetPoint2d.h"
27 #include "ModelAPI_Session.h"
28 #include "ModelAPI_AttributeString.h"
29 #include "ModelAPI_AttributeRefAttr.h"
30 #include "ModelAPI_AttributeReference.h"
31 #include "ModelAPI_EventReentrantMessage.h"
33 #include "GeomDataAPI_Point2D.h"
35 #include <ModuleBase_IPropertyPanel.h>
36 #include <ModuleBase_ISelectionActivate.h>
37 #include <ModuleBase_OperationFeature.h>
38 #include <ModuleBase_ModelWidget.h>
39 #include <ModuleBase_ViewerPrs.h>
40 #include <ModuleBase_WidgetSelector.h>
41 #include <ModuleBase_PageWidget.h>
42 #include <ModuleBase_PageBase.h>
43 #include <ModuleBase_WidgetFactory.h>
44 #include <ModuleBase_OperationDescription.h>
45 #include "ModuleBase_ToolBox.h"
46 #include "ModuleBase_ISelection.h"
47 #include "ModuleBase_ISelectionActivate.h"
49 #include <SketchPlugin_Feature.h>
50 #include <SketchPlugin_Line.h>
51 #include <SketchPlugin_MacroArc.h>
52 #include <SketchPlugin_MacroCircle.h>
53 #include <SketchPlugin_Point.h>
54 #include <SketchPlugin_Trim.h>
55 #include <SketchPlugin_Split.h>
57 #include <XGUI_Workshop.h>
58 #include <XGUI_ModuleConnector.h>
59 #include <XGUI_OperationMgr.h>
60 #include <XGUI_PropertyPanel.h>
61 #include <XGUI_ErrorMgr.h>
62 #include <XGUI_SelectionMgr.h>
64 #include <QToolButton>
66 //#define DEBUG_RESTART
68 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
69 : QObject(theWorkshop),
70 myWorkshop(theWorkshop),
71 myRestartingMode(RM_None),
72 myIsFlagsBlocked(false),
73 myIsInternalEditOperation(false),
74 myInternalActiveWidget(0),
75 myNoMoreWidgetsAttribute("")
79 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
83 ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
85 ModuleBase_ModelWidget* aWidget = 0;
89 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
91 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
92 if (aPanel) { // check for case when the operation is started but property panel is not filled
93 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
94 if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
95 aWidget = myInternalActiveWidget;
101 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
103 return myIsInternalEditOperation;
106 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
108 if (myIsInternalEditOperation) {
109 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
110 (myWorkshop->currentOperation());
112 FeaturePtr aFeature = aFOperation->feature();
113 QString anError = myWorkshop->module()->getFeatureError(aFeature);
114 // stop started internal edit operation as soon as the operation becomes invalid
115 // it is especially important for the sketch tangent arc feature
116 if (!anError.isEmpty()) {
117 aFOperation->setEditOperation(false);
118 //workshop()->operationMgr()->updateApplyOfOperations();
119 myIsInternalEditOperation = false;
120 updateAcceptAllAction();
126 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
128 bool aProcessed = false;
132 aProcessed = myIsInternalEditOperation;
138 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
143 //if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
144 //ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
145 // myWorkshop->currentOperation());
146 //CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
147 //if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
148 //copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
153 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
161 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
162 QMouseEvent* theEvent)
164 bool aProcessed = false;
168 if (myIsInternalEditOperation) {
169 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
170 (myWorkshop->currentOperation());
171 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
174 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
175 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
177 FeaturePtr aCurrentFeature = aFOperation->feature();
178 bool isLineFeature = false, isReentrantArcFeature = false;
179 std::string anAttributeOnStart;
180 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
181 anAttributeOnStart = SketchPlugin_Line::START_ID();
182 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
184 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
185 isReentrantArcFeature = true;
187 bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature;
188 if (aCanBeActivatedByMove) {
189 /// before restarting of operation we need to clear selection, as it may take part in
190 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
191 /// by mouse release when the operation was restarted.
192 workshop()->selector()->clearSelection();
194 myPreviousFeature = aFOperation->feature();
196 myPreviousFeature = FeaturePtr();
198 anActiveWidget = module()->activeWidget();
200 if (anActiveWidget && anActiveWidget->attributeID() == anAttributeOnStart) {
201 // it was not deactivated by preselection processing
202 aPanel->activateNextWidget(anActiveWidget);
205 // processing mouse move in active widget of restarted operation
206 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
207 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
209 aProcessor->mouseMoved(theWnd, theEvent);
216 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
217 QMouseEvent* /* theEvent*/)
219 return isActiveMgr() && myIsInternalEditOperation;
222 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
223 QMouseEvent* theEvent)
225 bool aProcessed = false;
229 if (myIsInternalEditOperation) {
230 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
231 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
233 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
234 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
236 // block of viewer update
237 // we need to block update content of the viewer because of Sketch Point feature
238 // in activate() the value of the point is initialized and it can be displayed
239 // but the default value is [0, 0]. So, we block update viewer contentent until
240 // onMouseRelease happens, which correct the point position
241 ModuleBase_Tools::blockUpdateViewer(true);
243 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
244 (myWorkshop->currentOperation());
245 myPreviousFeature = aFOperation->feature();
247 /// selection should be obtained from workshop before ask if the operation can be started as
248 /// the canStartOperation method performs commit/abort of previous operation.
249 /// Sometimes commit/abort
250 /// may cause selection clear(Sketch operation) as a result
251 /// it will be lost and is not used for preselection.
252 ModuleBase_ISelection* aSelection = myWorkshop->selection();
253 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
254 aSelection->getSelected(ModuleBase_ISelection::AllControls);
256 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
257 module()->sketchMgr()->activeSketch());
258 FeaturePtr anExternalCreatedFeature;
259 if (!aPreSelected.empty()) {
260 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
261 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
263 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
266 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
267 ObjectPtr anExternalObject = aPointWidget->getExternalObjectMgr()->getExternalObjectValidated();
268 // if external object has been created before staring new operation and is used as a parameter,
269 // it should be removed after the operation is restarted. (Circle feature, Projection)
270 if (anExternalObject.get())
271 anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject);
276 // remove created external feature
277 if (anExternalCreatedFeature.get()) {
278 QObjectPtrList anObjects;
279 anObjects.append(anExternalCreatedFeature);
280 workshop()->deleteFeatures(anObjects);
283 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
284 mySelectedObject = ObjectPtr();
285 mySelectedAttribute = AttributePtr();
287 myPreviousFeature = FeaturePtr();
290 // fill the first widget by the mouse event point
291 // if the active widget is not the first, it means that the restarted operation is filled by
292 // the current preselection.
293 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
294 module()->activeWidget());
295 //PartSet_WidgetPoint2D* aPoint2DWdg =
296 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
297 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
298 aPanel->findFirstAcceptingValueWidget());
299 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
300 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
301 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
302 if (!aPreSelected.empty())
303 aSelectedPrs = aPreSelected.front();
304 if (aSelectedPrs.get() && aSelectedPrs->object().get()
305 && !aSelectedPrs->object()->data()->isValid()) {
306 // the selected object was removed diring restart, e.g. presentable macro feature
307 // there are created objects to replace the object depending on created feature kind
308 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
310 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
311 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
312 //if (!aPreSelected.empty())
313 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
315 // unblock viewer update
316 ModuleBase_Tools::blockUpdateViewer(false);
322 //******************************************************
323 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
324 const std::shared_ptr<Events_Message>& theMessage)
326 ReentrantMessagePtr aReentrantMessage =
327 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
328 if (!aReentrantMessage.get())
331 // if feature has already filled the selected object, we should not overwrite it
332 if (!aReentrantMessage->selectedObject().get())
333 aReentrantMessage->setSelectedObject(mySelectedObject);
335 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
336 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
339 //void PartSet_SketcherReentrantMgr::onWidgetActivated()
341 // if (!isActiveMgr())
343 // if (!myIsInternalEditOperation)
346 // PartSet_Module* aModule = module();
347 // ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
348 // ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
349 // if (aFirstWidget != aPanel->activeWidget()) {
350 // ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
353 // myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
358 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
361 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
367 // we should avoid processing of the signal about no more widgets attributes and
368 // do this after the restart operaion is finished if it was called
369 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
370 // if it should be called after restart
371 if (myIsFlagsBlocked) {
372 myNoMoreWidgetsAttribute = thePreviousAttributeID;
376 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
377 (myWorkshop->currentOperation());
378 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
381 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
382 if (aFOperation->isNeedToBeAborted()) {
383 aFOperation->abort();
386 bool isStarted = false;
387 if (!module()->sketchMgr()->sketchSolverError()) {
388 if (myRestartingMode != RM_Forbided) {
389 myRestartingMode = RM_LastFeatureUsed;
390 isStarted = startInternalEdit(thePreviousAttributeID);
394 aFOperation->commit();
399 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
406 // empty previous attribute means that the Apply/Ok button has focus and the enter
407 // should not lead to start edition mode of the previous operation
408 if (thePreviousAttributeID.empty())
411 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
412 (myWorkshop->currentOperation());
413 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
416 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
418 if (!isSketchSolverError) {
419 myRestartingMode = RM_EmptyFeatureUsed;
420 isDone = startInternalEdit(thePreviousAttributeID);
426 void PartSet_SketcherReentrantMgr::onVertexSelected()
431 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
432 std::string anOperationId = anOperation->id().toStdString();
433 if (anOperationId == SketchPlugin_Line::ID() ||
434 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
435 /// If last line finished on vertex the lines creation sequence has to be break
436 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
437 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
438 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
439 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
440 bool aFoundWidget = false;
441 bool aFoundObligatory = false;
442 for (; anIt != aLast && !aFoundObligatory; anIt++) {
444 aFoundWidget = *anIt == anActiveWidget;
446 aFoundObligatory = (*anIt)->isObligatory();
448 if (!aFoundObligatory)
449 myRestartingMode = RM_Forbided;
453 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
456 if (isInternalEditActive()) {
457 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
458 (myWorkshop->currentOperation());
459 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
460 if (!aWidget->isModifiedInEdit().empty())
465 void PartSet_SketcherReentrantMgr::onBeforeStopped()
467 if (!isActiveMgr() || !myIsInternalEditOperation)
470 beforeStopInternalEdit();
473 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
475 return !isActiveMgr() || myRestartingMode == RM_None;
478 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
480 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
482 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
484 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
485 if (anActive) { // the manager is not active when the current operation is a usual Edit
486 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
487 (myWorkshop->currentOperation());
488 if (aFOperation->isEditOperation())
489 anActive = myIsInternalEditOperation;
495 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
498 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
502 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
503 /// event comes two times, so we should not start another internal edit operation
504 /// the Apply button becomes disabled becase the second additional internal feature is created
505 if (myIsInternalEditOperation)
508 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
509 (myWorkshop->currentOperation());
511 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
512 /// improvement to deselect automatically all eventual selected objects, when
513 // returning to the neutral point of the Sketcher or start internal edit
514 workshop()->selector()->clearSelection();
516 aFOperation->setEditOperation(true/*, false*/);
517 createInternalFeature();
519 myIsInternalEditOperation = true;
520 updateAcceptAllAction();
523 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
524 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
526 // activate selection filters of the first widget in the viewer
527 //onWidgetActivated();
529 // activate the last active widget in the Property Panel
530 if (!thePreviousAttributeID.empty()) {
531 ModuleBase_Operation* anEditOperation = module()->currentOperation();
532 if (anEditOperation) {
533 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
534 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
535 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
536 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
537 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
538 /// workaround for the same attributes used in different stacked widgets(attribute types)
539 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
541 aPreviousAttributeWidget = aWidgets[i];
544 // If the current widget is a selector, do nothing, it processes the mouse press
545 if (aPreviousAttributeWidget) {
546 if (!aPreviousAttributeWidget->isViewerSelector()) {
547 aPreviousAttributeWidget->focusTo();
548 aPreviousAttributeWidget->emitFocusInWidget();
549 aPreviousAttributeWidget->selectContent();
552 // in case of shape multi selector, the widget does not lose focus by filling
553 // like it is in shape selector. So, if enter is pressed, the multi shape selector
554 // control should be deactivated. The focus is moved to Apply button and there
555 // should not be active control visualized in property panel
556 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
557 aPanel->activateWidget(NULL, false);
559 // if there is no the next widget to be automatically activated,
560 // the Ok button in property
561 // panel should accept the focus(example is parallel constraint on sketch lines)
562 QToolButton* anOkBtn =
563 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
565 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
572 module()->sketchMgr()->clearClickedFlags();
577 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
579 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
580 (myWorkshop->currentOperation());
582 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
583 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
586 deleteInternalFeature();
589 void PartSet_SketcherReentrantMgr::restartOperation()
592 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
595 if (myIsInternalEditOperation) {
596 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
597 myWorkshop->currentOperation());
599 ModuleBase_ISelection* aSelection = myWorkshop->selection();
600 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
601 aSelection->getSelected(ModuleBase_ISelection::AllControls);
603 if (myInternalFeature.get())
604 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
605 module()->sketchMgr()->activeSketch());
607 myNoMoreWidgetsAttribute = "";
608 myIsFlagsBlocked = true;
609 /// launch has 'false' parameter to do not start new operation if the previous operation
610 /// is not committed. It is important for Line Sketch feature as it uses the previous
611 /// created feature parameter(to build coincidence), but by abort the previous is removed
612 module()->launchOperation(aFOperation->id(), true);
613 myIsFlagsBlocked = false;
616 // we should avoid processing of the signal about no more widgets attributes and
617 // do this after the restart operaion is finished if it was called
618 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
619 // if it should be called after restart
620 if (!myNoMoreWidgetsAttribute.empty()) {
621 onNoMoreWidgets(myNoMoreWidgetsAttribute);
622 myNoMoreWidgetsAttribute = "";
628 void PartSet_SketcherReentrantMgr::createInternalFeature()
630 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
631 (myWorkshop->currentOperation());
633 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
634 FeaturePtr anOperationFeature = aFOperation->feature();
636 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
637 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
640 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
641 << myInternalFeature->data()->name() << std::endl;
644 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
646 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
647 (aFOperation->propertyPanel());
649 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
650 myInternalWidget->setVisible(false);
652 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
654 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
655 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
657 aFactory.createWidget(anInternalPage);
658 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
660 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
661 bool isStoreValue = !aFOperation->isEditOperation() &&
662 !aWidget->getDefaultValue().empty() &&
663 !aWidget->isComputedDefault();
664 aWidget->setFeature(myInternalFeature, isStoreValue);
665 if (!isStoreValue && isFeatureChanged)
666 aWidget->restoreValue();
669 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
672 myInternalActiveWidget = aFirstWidget;
676 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
679 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
680 << myInternalFeature->data()->name() << std::endl;
682 if (myInternalActiveWidget)
683 myInternalActiveWidget = 0;
684 delete myInternalWidget;
685 myInternalWidget = 0;
687 QObjectPtrList anObjects;
688 anObjects.append(myInternalFeature);
689 workshop()->deleteFeatures(anObjects);
690 myInternalFeature = FeaturePtr();
693 void PartSet_SketcherReentrantMgr::resetFlags()
695 if (!myIsFlagsBlocked) {
696 myIsInternalEditOperation = false;
697 updateAcceptAllAction();
698 myRestartingMode = RM_None;
699 myReentrantMessage = std::shared_ptr<Events_Message>();
703 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
704 const FeaturePtr& theNewFeature,
705 const CompositeFeaturePtr& theSketch,
706 const bool /*isTemporary*/)
708 bool aChanged = false;
709 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
710 !theSourceFeature->data()->isValid())
714 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
715 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
719 std::string aFeatureKind = theSourceFeature->getKind();
720 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
721 // Initialize new line with first point equal to end of previous
722 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
723 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
724 aSFData->attribute(SketchPlugin_Line::END_ID()));
725 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
726 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
727 aNFData->attribute(SketchPlugin_Line::START_ID()));
728 aNPoint->setValue(aSPoint->x(), aSPoint->y());
729 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
731 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
732 aSFData->attribute(SketchPlugin_Line::END_ID()));
733 aNPoint->setValue(aSPoint->x(), aSPoint->y());
735 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
737 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
738 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
739 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
740 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
741 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
742 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
745 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
747 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
748 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
749 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
750 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
751 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
752 //// if the arc is tangent, set coincidence to end point of the previous arc
753 //std::string anArcType = aSourceFeatureTypeAttr->value();
754 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
755 // // get the last point of the previuos arc feature(geom point 2d)
756 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
757 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
758 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
759 // aSData->attribute(SketchPlugin_Arc::END_ID()));
760 // // get point attribute on the current feature
761 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
762 // SketchPlugin_Arc::TANGENT_POINT_ID());
763 // aTangentPointAttr->setAttr(aSPointAttr);
765 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
766 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
767 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
768 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
771 //ModuleBase_Tools::flushUpdated(theNewFeature);
774 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
775 aFeatureKind == SketchPlugin_Split::ID()) {
776 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
777 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
778 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
779 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
780 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
781 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
782 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
783 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
784 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
785 theNewFeature->data()->attribute(aPreviewObjectAttribute));
786 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
787 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
788 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
789 theSourceFeature->data()->attribute(aPreviewPointAttribute));
790 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
791 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
792 theNewFeature->data()->attribute(aPreviewPointAttribute));
793 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
798 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
799 const CompositeFeaturePtr& /*theSketch*/) const
801 bool aTangentArc = false;
802 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
804 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
805 FeaturePtr aFeature = aFOperation->feature();
806 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
807 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
808 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
809 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
815 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
817 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
819 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
822 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
824 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
825 return aConnector->workshop();
828 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
830 return dynamic_cast<PartSet_Module*>(myWorkshop->module());