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 =
268 aPointWidget->getExternalObjectMgr()->getExternalObjectValidated();
269 // if external object is during reentrant operation and is used as a parameter of feature
270 // it should be removed after the operation is restarted. (Circle feature, Projection)
271 if (anExternalObject.get())
272 anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject);
277 // remove created external feature
278 if (anExternalCreatedFeature.get()) {
279 QObjectPtrList anObjects;
280 anObjects.append(anExternalCreatedFeature);
281 workshop()->deleteFeatures(anObjects);
284 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
285 mySelectedObject = ObjectPtr();
286 mySelectedAttribute = AttributePtr();
288 myPreviousFeature = FeaturePtr();
291 // fill the first widget by the mouse event point
292 // if the active widget is not the first, it means that the restarted operation is filled by
293 // the current preselection.
294 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
295 module()->activeWidget());
296 //PartSet_WidgetPoint2D* aPoint2DWdg =
297 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
298 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
299 aPanel->findFirstAcceptingValueWidget());
300 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
301 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
302 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
303 if (!aPreSelected.empty())
304 aSelectedPrs = aPreSelected.front();
305 if (aSelectedPrs.get() && aSelectedPrs->object().get()
306 && !aSelectedPrs->object()->data()->isValid()) {
307 // the selected object was removed diring restart, e.g. presentable macro feature
308 // there are created objects to replace the object depending on created feature kind
309 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
311 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
312 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
313 //if (!aPreSelected.empty())
314 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
316 // unblock viewer update
317 ModuleBase_Tools::blockUpdateViewer(false);
323 //******************************************************
324 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
325 const std::shared_ptr<Events_Message>& theMessage)
327 ReentrantMessagePtr aReentrantMessage =
328 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
329 if (!aReentrantMessage.get())
332 // if feature has already filled the selected object, we should not overwrite it
333 if (!aReentrantMessage->selectedObject().get())
334 aReentrantMessage->setSelectedObject(mySelectedObject);
336 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
337 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
340 //void PartSet_SketcherReentrantMgr::onWidgetActivated()
342 // if (!isActiveMgr())
344 // if (!myIsInternalEditOperation)
347 // PartSet_Module* aModule = module();
348 // ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
349 // ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
350 // if (aFirstWidget != aPanel->activeWidget()) {
351 // ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
354 // myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
359 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
362 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
368 // we should avoid processing of the signal about no more widgets attributes and
369 // do this after the restart operaion is finished if it was called
370 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
371 // if it should be called after restart
372 if (myIsFlagsBlocked) {
373 myNoMoreWidgetsAttribute = thePreviousAttributeID;
377 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
378 (myWorkshop->currentOperation());
379 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
382 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
383 if (aFOperation->isNeedToBeAborted()) {
384 aFOperation->abort();
387 bool isStarted = false;
388 if (!module()->sketchMgr()->sketchSolverError()) {
389 if (myRestartingMode != RM_Forbided) {
390 myRestartingMode = RM_LastFeatureUsed;
391 isStarted = startInternalEdit(thePreviousAttributeID);
395 aFOperation->commit();
400 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
407 // empty previous attribute means that the Apply/Ok button has focus and the enter
408 // should not lead to start edition mode of the previous operation
409 if (thePreviousAttributeID.empty())
412 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
413 (myWorkshop->currentOperation());
414 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
417 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
419 if (!isSketchSolverError) {
420 myRestartingMode = RM_EmptyFeatureUsed;
421 isDone = startInternalEdit(thePreviousAttributeID);
427 void PartSet_SketcherReentrantMgr::onVertexSelected()
432 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
433 std::string anOperationId = anOperation->id().toStdString();
434 if (anOperationId == SketchPlugin_Line::ID() ||
435 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
436 /// If last line finished on vertex the lines creation sequence has to be break
437 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
438 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
439 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
440 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
441 bool aFoundWidget = false;
442 bool aFoundObligatory = false;
443 for (; anIt != aLast && !aFoundObligatory; anIt++) {
445 aFoundWidget = *anIt == anActiveWidget;
447 aFoundObligatory = (*anIt)->isObligatory();
449 if (!aFoundObligatory)
450 myRestartingMode = RM_Forbided;
454 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
457 if (isInternalEditActive()) {
458 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
459 (myWorkshop->currentOperation());
460 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
461 if (!aWidget->isModifiedInEdit().empty())
466 void PartSet_SketcherReentrantMgr::onBeforeStopped()
468 if (!isActiveMgr() || !myIsInternalEditOperation)
471 beforeStopInternalEdit();
474 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
476 return !isActiveMgr() || myRestartingMode == RM_None;
479 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
481 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
483 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
485 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
486 if (anActive) { // the manager is not active when the current operation is a usual Edit
487 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
488 (myWorkshop->currentOperation());
489 if (aFOperation->isEditOperation())
490 anActive = myIsInternalEditOperation;
496 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
499 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
503 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
504 /// event comes two times, so we should not start another internal edit operation
505 /// the Apply button becomes disabled becase the second additional internal feature is created
506 if (myIsInternalEditOperation)
509 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
510 (myWorkshop->currentOperation());
512 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
513 /// improvement to deselect automatically all eventual selected objects, when
514 // returning to the neutral point of the Sketcher or start internal edit
515 workshop()->selector()->clearSelection();
517 aFOperation->setEditOperation(true/*, false*/);
518 createInternalFeature();
520 myIsInternalEditOperation = true;
521 updateAcceptAllAction();
524 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
525 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
527 // activate selection filters of the first widget in the viewer
528 //onWidgetActivated();
530 // activate the last active widget in the Property Panel
531 if (!thePreviousAttributeID.empty()) {
532 ModuleBase_Operation* anEditOperation = module()->currentOperation();
533 if (anEditOperation) {
534 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
535 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
536 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
537 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
538 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
539 /// workaround for the same attributes used in different stacked widgets(attribute types)
540 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
542 aPreviousAttributeWidget = aWidgets[i];
545 // If the current widget is a selector, do nothing, it processes the mouse press
546 if (aPreviousAttributeWidget) {
547 if (!aPreviousAttributeWidget->isViewerSelector()) {
548 aPreviousAttributeWidget->focusTo();
549 aPreviousAttributeWidget->emitFocusInWidget();
550 aPreviousAttributeWidget->selectContent();
553 // in case of shape multi selector, the widget does not lose focus by filling
554 // like it is in shape selector. So, if enter is pressed, the multi shape selector
555 // control should be deactivated. The focus is moved to Apply button and there
556 // should not be active control visualized in property panel
557 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
558 aPanel->activateWidget(NULL, false);
560 // if there is no the next widget to be automatically activated,
561 // the Ok button in property
562 // panel should accept the focus(example is parallel constraint on sketch lines)
563 QToolButton* anOkBtn =
564 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
566 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
573 module()->sketchMgr()->clearClickedFlags();
578 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
580 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
581 (myWorkshop->currentOperation());
583 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
584 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
587 deleteInternalFeature();
590 void PartSet_SketcherReentrantMgr::restartOperation()
593 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
596 if (myIsInternalEditOperation) {
597 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
598 myWorkshop->currentOperation());
600 ModuleBase_ISelection* aSelection = myWorkshop->selection();
601 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
602 aSelection->getSelected(ModuleBase_ISelection::AllControls);
604 if (myInternalFeature.get())
605 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
606 module()->sketchMgr()->activeSketch());
608 myNoMoreWidgetsAttribute = "";
609 myIsFlagsBlocked = true;
610 /// launch has 'false' parameter to do not start new operation if the previous operation
611 /// is not committed. It is important for Line Sketch feature as it uses the previous
612 /// created feature parameter(to build coincidence), but by abort the previous is removed
613 module()->launchOperation(aFOperation->id(), true);
614 myIsFlagsBlocked = false;
617 // we should avoid processing of the signal about no more widgets attributes and
618 // do this after the restart operaion is finished if it was called
619 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
620 // if it should be called after restart
621 if (!myNoMoreWidgetsAttribute.empty()) {
622 onNoMoreWidgets(myNoMoreWidgetsAttribute);
623 myNoMoreWidgetsAttribute = "";
629 void PartSet_SketcherReentrantMgr::createInternalFeature()
631 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
632 (myWorkshop->currentOperation());
634 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
635 FeaturePtr anOperationFeature = aFOperation->feature();
637 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
638 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
641 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
642 << myInternalFeature->data()->name() << std::endl;
645 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
647 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
648 (aFOperation->propertyPanel());
650 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
651 myInternalWidget->setVisible(false);
653 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
655 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
656 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
658 aFactory.createWidget(anInternalPage);
659 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
661 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
662 bool isStoreValue = !aFOperation->isEditOperation() &&
663 !aWidget->getDefaultValue().empty() &&
664 !aWidget->isComputedDefault();
665 aWidget->setFeature(myInternalFeature, isStoreValue);
666 if (!isStoreValue && isFeatureChanged)
667 aWidget->restoreValue();
670 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
673 myInternalActiveWidget = aFirstWidget;
677 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
680 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
681 << myInternalFeature->data()->name() << std::endl;
683 if (myInternalActiveWidget)
684 myInternalActiveWidget = 0;
685 delete myInternalWidget;
686 myInternalWidget = 0;
688 QObjectPtrList anObjects;
689 anObjects.append(myInternalFeature);
690 workshop()->deleteFeatures(anObjects);
691 myInternalFeature = FeaturePtr();
694 void PartSet_SketcherReentrantMgr::resetFlags()
696 if (!myIsFlagsBlocked) {
697 myIsInternalEditOperation = false;
698 updateAcceptAllAction();
699 myRestartingMode = RM_None;
700 myReentrantMessage = std::shared_ptr<Events_Message>();
704 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
705 const FeaturePtr& theNewFeature,
706 const CompositeFeaturePtr& theSketch,
707 const bool /*isTemporary*/)
709 bool aChanged = false;
710 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
711 !theSourceFeature->data()->isValid())
715 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
716 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
720 std::string aFeatureKind = theSourceFeature->getKind();
721 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
722 // Initialize new line with first point equal to end of previous
723 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
724 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
725 aSFData->attribute(SketchPlugin_Line::END_ID()));
726 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
727 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
728 aNFData->attribute(SketchPlugin_Line::START_ID()));
729 aNPoint->setValue(aSPoint->x(), aSPoint->y());
730 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
732 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
733 aSFData->attribute(SketchPlugin_Line::END_ID()));
734 aNPoint->setValue(aSPoint->x(), aSPoint->y());
736 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
738 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
739 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
740 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
741 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
742 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
743 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
746 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
748 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
749 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
750 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
751 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
752 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
753 //// if the arc is tangent, set coincidence to end point of the previous arc
754 //std::string anArcType = aSourceFeatureTypeAttr->value();
755 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
756 // // get the last point of the previuos arc feature(geom point 2d)
757 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
758 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
759 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
760 // aSData->attribute(SketchPlugin_Arc::END_ID()));
761 // // get point attribute on the current feature
762 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
763 // SketchPlugin_Arc::TANGENT_POINT_ID());
764 // aTangentPointAttr->setAttr(aSPointAttr);
766 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
767 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
768 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
769 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
772 //ModuleBase_Tools::flushUpdated(theNewFeature);
775 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
776 aFeatureKind == SketchPlugin_Split::ID()) {
777 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
778 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
779 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
780 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
781 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
782 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
783 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
784 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
785 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
786 theNewFeature->data()->attribute(aPreviewObjectAttribute));
787 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
788 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
789 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
790 theSourceFeature->data()->attribute(aPreviewPointAttribute));
791 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
792 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
793 theNewFeature->data()->attribute(aPreviewPointAttribute));
794 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
799 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
800 const CompositeFeaturePtr& /*theSketch*/) const
802 bool aTangentArc = false;
803 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
805 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
806 FeaturePtr aFeature = aFOperation->feature();
807 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
808 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
809 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
810 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
816 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
818 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
820 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
823 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
825 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
826 return aConnector->workshop();
829 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
831 return dynamic_cast<PartSet_Module*>(myWorkshop->module());