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_Module.h"
23 #include "PartSet_SketcherMgr.h"
24 #include "PartSet_WidgetPoint2d.h"
26 #include "ModelAPI_Session.h"
27 #include "ModelAPI_AttributeString.h"
28 #include "ModelAPI_AttributeRefAttr.h"
29 #include "ModelAPI_AttributeReference.h"
30 #include "ModelAPI_EventReentrantMessage.h"
32 #include "GeomDataAPI_Point2D.h"
34 #include <ModuleBase_IPropertyPanel.h>
35 #include <ModuleBase_OperationFeature.h>
36 #include <ModuleBase_ModelWidget.h>
37 #include <ModuleBase_ViewerPrs.h>
38 #include <ModuleBase_WidgetSelector.h>
39 #include <ModuleBase_PageWidget.h>
40 #include <ModuleBase_PageBase.h>
41 #include <ModuleBase_WidgetFactory.h>
42 #include <ModuleBase_OperationDescription.h>
43 #include "ModuleBase_ToolBox.h"
44 #include "ModuleBase_ISelection.h"
46 #include <SketchPlugin_Feature.h>
47 #include <SketchPlugin_Line.h>
48 #include <SketchPlugin_MacroArc.h>
49 #include <SketchPlugin_MacroCircle.h>
50 #include <SketchPlugin_Point.h>
51 #include <SketchPlugin_Trim.h>
52 #include <SketchPlugin_Split.h>
54 #include <XGUI_Workshop.h>
55 #include <XGUI_ModuleConnector.h>
56 #include <XGUI_OperationMgr.h>
57 #include <XGUI_PropertyPanel.h>
58 #include <XGUI_ErrorMgr.h>
59 #include <XGUI_SelectionMgr.h>
61 #include <QToolButton>
63 //#define DEBUG_RESTART
65 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
66 : QObject(theWorkshop),
67 myWorkshop(theWorkshop),
68 myRestartingMode(RM_None),
69 myIsFlagsBlocked(false),
70 myIsInternalEditOperation(false),
71 myInternalActiveWidget(0),
72 myNoMoreWidgetsAttribute("")
76 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
80 ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
82 ModuleBase_ModelWidget* aWidget = 0;
86 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
88 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
89 if (aPanel) { // check for case when the operation is started but property panel is not filled
90 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
91 if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
92 aWidget = myInternalActiveWidget;
98 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
100 return myIsInternalEditOperation;
103 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
105 if (myIsInternalEditOperation) {
106 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
107 (myWorkshop->currentOperation());
109 FeaturePtr aFeature = aFOperation->feature();
110 QString anError = myWorkshop->module()->getFeatureError(aFeature);
111 // stop started internal edit operation as soon as the operation becomes invalid
112 // it is especially important for the sketch tangent arc feature
113 if (!anError.isEmpty()) {
114 aFOperation->setEditOperation(false);
115 //workshop()->operationMgr()->updateApplyOfOperations();
116 myIsInternalEditOperation = false;
117 updateAcceptAllAction();
123 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
125 bool aProcessed = false;
129 aProcessed = myIsInternalEditOperation;
135 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
140 //if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
141 //ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
142 // myWorkshop->currentOperation());
143 //CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
144 //if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
145 //copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
150 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
158 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
159 QMouseEvent* theEvent)
161 bool aProcessed = false;
165 if (myIsInternalEditOperation) {
166 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
167 (myWorkshop->currentOperation());
168 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
171 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
172 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
174 FeaturePtr aCurrentFeature = aFOperation->feature();
175 bool isLineFeature = false, isReentrantArcFeature = false;
176 std::string anAttributeOnStart;
177 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
178 anAttributeOnStart = SketchPlugin_Line::START_ID();
179 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
181 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
182 isReentrantArcFeature = true;
184 bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature;
185 if (aCanBeActivatedByMove) {
186 /// before restarting of operation we need to clear selection, as it may take part in
187 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
188 /// by mouse release when the operation was restarted.
189 workshop()->selector()->clearSelection();
191 myPreviousFeature = aFOperation->feature();
193 myPreviousFeature = FeaturePtr();
195 anActiveWidget = module()->activeWidget();
197 if (anActiveWidget && anActiveWidget->attributeID() == anAttributeOnStart) {
198 // it was not deactivated by preselection processing
199 aPanel->activateNextWidget(anActiveWidget);
202 // processing mouse move in active widget of restarted operation
203 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
204 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
206 aProcessor->mouseMoved(theWnd, theEvent);
213 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
214 QMouseEvent* /* theEvent*/)
216 return isActiveMgr() && myIsInternalEditOperation;
219 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
220 QMouseEvent* theEvent)
222 bool aProcessed = false;
226 if (myIsInternalEditOperation) {
227 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
228 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
230 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
231 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
233 // block of viewer update
234 // we need to block update content of the viewer because of Sketch Point feature
235 // in activate() the value of the point is initialized and it can be displayed
236 // but the default value is [0, 0]. So, we block update viewer contentent until
237 // onMouseRelease happens, which correct the point position
238 ModuleBase_Tools::blockUpdateViewer(true);
240 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
241 (myWorkshop->currentOperation());
242 myPreviousFeature = aFOperation->feature();
244 /// selection should be obtained from workshop before ask if the operation can be started as
245 /// the canStartOperation method performs commit/abort of previous operation.
246 /// Sometimes commit/abort
247 /// may cause selection clear(Sketch operation) as a result
248 /// it will be lost and is not used for preselection.
249 ModuleBase_ISelection* aSelection = myWorkshop->selection();
250 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
251 aSelection->getSelected(ModuleBase_ISelection::AllControls);
253 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
254 module()->sketchMgr()->activeSketch());
255 if (!aPreSelected.empty()) {
256 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
257 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
259 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
262 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
267 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
268 mySelectedObject = ObjectPtr();
269 mySelectedAttribute = AttributePtr();
271 myPreviousFeature = FeaturePtr();
274 // fill the first widget by the mouse event point
275 // if the active widget is not the first, it means that the restarted operation is filled by
276 // the current preselection.
277 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
278 module()->activeWidget());
279 //PartSet_WidgetPoint2D* aPoint2DWdg =
280 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
281 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
282 aPanel->findFirstAcceptingValueWidget());
283 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
284 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
285 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
286 if (!aPreSelected.empty())
287 aSelectedPrs = aPreSelected.front();
288 if (aSelectedPrs.get() && aSelectedPrs->object().get()
289 && !aSelectedPrs->object()->data()->isValid()) {
290 // the selected object was removed diring restart, e.g. presentable macro feature
291 // there are created objects to replace the object depending on created feature kind
292 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
294 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
295 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
296 //if (!aPreSelected.empty())
297 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
299 // unblock viewer update
300 ModuleBase_Tools::blockUpdateViewer(false);
306 //******************************************************
307 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
308 const std::shared_ptr<Events_Message>& theMessage)
310 ReentrantMessagePtr aReentrantMessage =
311 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
312 if (!aReentrantMessage.get())
315 // if feature has already filled the selected object, we should not overwrite it
316 if (!aReentrantMessage->selectedObject().get())
317 aReentrantMessage->setSelectedObject(mySelectedObject);
319 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
320 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
323 void PartSet_SketcherReentrantMgr::onWidgetActivated()
327 if (!myIsInternalEditOperation)
330 PartSet_Module* aModule = module();
331 ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
332 ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
333 if (aFirstWidget != aPanel->activeWidget()) {
334 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
336 aWSelector->activateSelectionAndFilters(true);
340 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
343 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
349 // we should avoid processing of the signal about no more widgets attributes and
350 // do this after the restart operaion is finished if it was called
351 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
352 // if it should be called after restart
353 if (myIsFlagsBlocked) {
354 myNoMoreWidgetsAttribute = thePreviousAttributeID;
358 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
359 (myWorkshop->currentOperation());
360 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
363 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
364 bool isStarted = false;
365 if (!module()->sketchMgr()->sketchSolverError()) {
366 if (myRestartingMode != RM_Forbided) {
367 myRestartingMode = RM_LastFeatureUsed;
368 isStarted = startInternalEdit(thePreviousAttributeID);
372 aFOperation->commit();
376 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
383 // empty previous attribute means that the Apply/Ok button has focus and the enter
384 // should not lead to start edition mode of the previous operation
385 if (thePreviousAttributeID.empty())
388 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
389 (myWorkshop->currentOperation());
390 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
393 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
395 if (!isSketchSolverError) {
396 myRestartingMode = RM_EmptyFeatureUsed;
397 isDone = startInternalEdit(thePreviousAttributeID);
403 void PartSet_SketcherReentrantMgr::onVertexSelected()
408 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
409 std::string anOperationId = anOperation->id().toStdString();
410 if (anOperationId == SketchPlugin_Line::ID() ||
411 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
412 /// If last line finished on vertex the lines creation sequence has to be break
413 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
414 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
415 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
416 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
417 bool aFoundWidget = false;
418 bool aFoundObligatory = false;
419 for (; anIt != aLast && !aFoundObligatory; anIt++) {
421 aFoundWidget = *anIt == anActiveWidget;
423 aFoundObligatory = (*anIt)->isObligatory();
425 if (!aFoundObligatory)
426 myRestartingMode = RM_Forbided;
430 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
433 if (isInternalEditActive()) {
434 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
435 (myWorkshop->currentOperation());
436 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
437 if (!aWidget->isModifiedInEdit().empty())
442 void PartSet_SketcherReentrantMgr::onBeforeStopped()
444 if (!isActiveMgr() || !myIsInternalEditOperation)
447 beforeStopInternalEdit();
450 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
452 return !isActiveMgr() || myRestartingMode == RM_None;
455 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
457 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
459 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
461 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
462 if (anActive) { // the manager is not active when the current operation is a usual Edit
463 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
464 (myWorkshop->currentOperation());
465 if (aFOperation->isEditOperation())
466 anActive = myIsInternalEditOperation;
472 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
475 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
479 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
480 /// event comes two times, so we should not start another internal edit operation
481 /// the Apply button becomes disabled becase the second additional internal feature is created
482 if (myIsInternalEditOperation)
485 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
486 (myWorkshop->currentOperation());
488 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
489 /// improvement to deselect automatically all eventual selected objects, when
490 // returning to the neutral point of the Sketcher or start internal edit
491 workshop()->selector()->clearSelection();
493 aFOperation->setEditOperation(true/*, false*/);
494 createInternalFeature();
496 myIsInternalEditOperation = true;
497 updateAcceptAllAction();
500 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
501 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
503 // activate selection filters of the first widget in the viewer
506 // activate the last active widget in the Property Panel
507 if (!thePreviousAttributeID.empty()) {
508 ModuleBase_Operation* anEditOperation = module()->currentOperation();
509 if (anEditOperation) {
510 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
511 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
512 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
513 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
514 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
515 /// workaround for the same attributes used in different stacked widgets(attribute types)
516 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
518 aPreviousAttributeWidget = aWidgets[i];
521 // If the current widget is a selector, do nothing, it processes the mouse press
522 if (aPreviousAttributeWidget) {
523 if (!aPreviousAttributeWidget->isViewerSelector()) {
524 aPreviousAttributeWidget->focusTo();
525 aPreviousAttributeWidget->emitFocusInWidget();
526 aPreviousAttributeWidget->selectContent();
529 // in case of shape multi selector, the widget does not lose focus by filling
530 // like it is in shape selector. So, if enter is pressed, the multi shape selector
531 // control should be deactivated. The focus is moved to Apply button and there
532 // should not be active control visualized in property panel
533 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
534 aPanel->activateWidget(NULL, false);
536 // if there is no the next widget to be automatically activated,
537 // the Ok button in property
538 // panel should accept the focus(example is parallel constraint on sketch lines)
539 QToolButton* anOkBtn =
540 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
542 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
549 module()->sketchMgr()->clearClickedFlags();
554 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
556 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
557 (myWorkshop->currentOperation());
559 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
560 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
563 deleteInternalFeature();
566 void PartSet_SketcherReentrantMgr::restartOperation()
569 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
572 if (myIsInternalEditOperation) {
573 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
574 myWorkshop->currentOperation());
576 ModuleBase_ISelection* aSelection = myWorkshop->selection();
577 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
578 aSelection->getSelected(ModuleBase_ISelection::AllControls);
580 if (myInternalFeature.get())
581 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
582 module()->sketchMgr()->activeSketch());
584 myNoMoreWidgetsAttribute = "";
585 myIsFlagsBlocked = true;
586 /// launch has 'false' parameter to do not start new operation if the previous operation
587 /// is not committed. It is important for Line Sketch feature as it uses the previous
588 /// created feature parameter(to build coincidence), but by abort the previous is removed
589 module()->launchOperation(aFOperation->id(), true);
590 myIsFlagsBlocked = false;
593 // we should avoid processing of the signal about no more widgets attributes and
594 // do this after the restart operaion is finished if it was called
595 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
596 // if it should be called after restart
597 if (!myNoMoreWidgetsAttribute.empty()) {
598 onNoMoreWidgets(myNoMoreWidgetsAttribute);
599 myNoMoreWidgetsAttribute = "";
605 void PartSet_SketcherReentrantMgr::createInternalFeature()
607 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
608 (myWorkshop->currentOperation());
610 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
611 FeaturePtr anOperationFeature = aFOperation->feature();
613 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
614 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
617 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
618 << myInternalFeature->data()->name() << std::endl;
621 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
623 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
624 (aFOperation->propertyPanel());
626 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
627 myInternalWidget->setVisible(false);
629 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
631 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
632 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
634 aFactory.createWidget(anInternalPage);
635 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
637 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
638 bool isStoreValue = !aFOperation->isEditOperation() &&
639 !aWidget->getDefaultValue().empty() &&
640 !aWidget->isComputedDefault();
641 aWidget->setFeature(myInternalFeature, isStoreValue);
642 if (!isStoreValue && isFeatureChanged)
643 aWidget->restoreValue();
646 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
649 myInternalActiveWidget = aFirstWidget;
653 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
656 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
657 << myInternalFeature->data()->name() << std::endl;
659 if (myInternalActiveWidget) {
660 ModuleBase_WidgetSelector* aWSelector =
661 dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
663 aWSelector->activateSelectionAndFilters(false);
664 myInternalActiveWidget = 0;
666 delete myInternalWidget;
667 myInternalWidget = 0;
669 QObjectPtrList anObjects;
670 anObjects.append(myInternalFeature);
671 workshop()->deleteFeatures(anObjects);
672 myInternalFeature = FeaturePtr();
675 void PartSet_SketcherReentrantMgr::resetFlags()
677 if (!myIsFlagsBlocked) {
678 myIsInternalEditOperation = false;
679 updateAcceptAllAction();
680 myRestartingMode = RM_None;
681 myReentrantMessage = std::shared_ptr<Events_Message>();
685 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
686 const FeaturePtr& theNewFeature,
687 const CompositeFeaturePtr& theSketch,
688 const bool /*isTemporary*/)
690 bool aChanged = false;
691 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
692 !theSourceFeature->data()->isValid())
696 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
697 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
701 std::string aFeatureKind = theSourceFeature->getKind();
702 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
703 // Initialize new line with first point equal to end of previous
704 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
705 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
706 aSFData->attribute(SketchPlugin_Line::END_ID()));
707 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
708 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
709 aNFData->attribute(SketchPlugin_Line::START_ID()));
710 aNPoint->setValue(aSPoint->x(), aSPoint->y());
711 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
713 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
714 aSFData->attribute(SketchPlugin_Line::END_ID()));
715 aNPoint->setValue(aSPoint->x(), aSPoint->y());
717 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
719 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
720 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
721 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
722 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
723 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
724 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
727 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
729 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
730 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
731 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
732 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
733 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
734 //// if the arc is tangent, set coincidence to end point of the previous arc
735 //std::string anArcType = aSourceFeatureTypeAttr->value();
736 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
737 // // get the last point of the previuos arc feature(geom point 2d)
738 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
739 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
740 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
741 // aSData->attribute(SketchPlugin_Arc::END_ID()));
742 // // get point attribute on the current feature
743 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
744 // SketchPlugin_Arc::TANGENT_POINT_ID());
745 // aTangentPointAttr->setAttr(aSPointAttr);
747 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
748 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
749 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
750 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
753 //ModuleBase_Tools::flushUpdated(theNewFeature);
756 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
757 aFeatureKind == SketchPlugin_Split::ID()) {
758 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
759 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
760 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
761 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
762 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
763 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
764 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
765 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
766 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
767 theNewFeature->data()->attribute(aPreviewObjectAttribute));
768 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
769 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
770 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
771 theSourceFeature->data()->attribute(aPreviewPointAttribute));
772 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
773 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
774 theNewFeature->data()->attribute(aPreviewPointAttribute));
775 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
780 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
781 const CompositeFeaturePtr& /*theSketch*/) const
783 bool aTangentArc = false;
784 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
786 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
787 FeaturePtr aFeature = aFOperation->feature();
788 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
789 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
790 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
791 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
797 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
799 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
801 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
804 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
806 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
807 return aConnector->workshop();
810 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
812 return dynamic_cast<PartSet_Module*>(myWorkshop->module());