1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "PartSet_SketcherReentrantMgr.h"
21 #include "PartSet_ExternalObjectsMgr.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_ISelectionActivate.h>
36 #include <ModuleBase_OperationFeature.h>
37 #include <ModuleBase_ModelWidget.h>
38 #include <ModuleBase_ViewerPrs.h>
39 #include <ModuleBase_WidgetSelector.h>
40 #include <ModuleBase_PageWidget.h>
41 #include <ModuleBase_PageBase.h>
42 #include <ModuleBase_WidgetFactory.h>
43 #include <ModuleBase_OperationDescription.h>
44 #include "ModuleBase_ToolBox.h"
45 #include "ModuleBase_ISelection.h"
47 #include <SketchPlugin_Feature.h>
48 #include <SketchPlugin_Line.h>
49 #include <SketchPlugin_MacroArc.h>
50 #include <SketchPlugin_MacroCircle.h>
51 #include <SketchPlugin_Point.h>
52 #include <SketchPlugin_Trim.h>
53 #include <SketchPlugin_Split.h>
55 #include <XGUI_Workshop.h>
56 #include <XGUI_ModuleConnector.h>
57 #include <XGUI_OperationMgr.h>
58 #include <XGUI_PropertyPanel.h>
59 #include <XGUI_ErrorMgr.h>
60 #include <XGUI_SelectionMgr.h>
62 #include <QToolButton>
64 //#define DEBUG_RESTART
66 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
67 : QObject(theWorkshop),
68 myWorkshop(theWorkshop),
69 myRestartingMode(RM_None),
70 myIsFlagsBlocked(false),
71 myIsInternalEditOperation(false),
72 myNoMoreWidgetsAttribute("")
76 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
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 FeaturePtr anExternalCreatedFeature;
238 if (!aPreSelected.empty()) {
239 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
240 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
242 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
245 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
246 ObjectPtr anExternalObject =
247 aPointWidget->getExternalObjectMgr()->getExternalObjectValidated();
248 // if external object is during reentrant operation and is used as a parameter of feature
249 // it should be removed after the operation is restarted. (Circle feature, Projection)
250 if (anExternalObject.get())
251 anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject);
256 // remove created external feature
257 if (anExternalCreatedFeature.get()) {
258 QObjectPtrList anObjects;
259 anObjects.append(anExternalCreatedFeature);
260 workshop()->deleteFeatures(anObjects);
263 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
264 mySelectedObject = ObjectPtr();
265 mySelectedAttribute = AttributePtr();
267 myPreviousFeature = FeaturePtr();
270 // fill the first widget by the mouse event point
271 // if the active widget is not the first, it means that the restarted operation is filled by
272 // the current preselection.
273 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
274 module()->activeWidget());
275 //PartSet_WidgetPoint2D* aPoint2DWdg =
276 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
277 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
278 aPanel->findFirstAcceptingValueWidget());
279 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
280 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
281 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
282 if (!aPreSelected.empty())
283 aSelectedPrs = aPreSelected.front();
284 if (aSelectedPrs.get() && aSelectedPrs->object().get()
285 && !aSelectedPrs->object()->data()->isValid()) {
286 // the selected object was removed diring restart, e.g. presentable macro feature
287 // there are created objects to replace the object depending on created feature kind
288 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
290 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
291 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
292 //if (!aPreSelected.empty())
293 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
295 // unblock viewer update
296 ModuleBase_Tools::blockUpdateViewer(false);
302 //******************************************************
303 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
304 const std::shared_ptr<Events_Message>& theMessage)
306 ReentrantMessagePtr aReentrantMessage =
307 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
308 if (!aReentrantMessage.get())
311 // if feature has already filled the selected object, we should not overwrite it
312 if (!aReentrantMessage->selectedObject().get())
313 aReentrantMessage->setSelectedObject(mySelectedObject);
315 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
316 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
319 //void PartSet_SketcherReentrantMgr::onWidgetActivated()
321 // if (!isActiveMgr())
323 // if (!myIsInternalEditOperation)
326 // PartSet_Module* aModule = module();
327 // ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
328 // ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
329 // if (aFirstWidget != aPanel->activeWidget()) {
330 // ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
333 // myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
338 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
341 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
347 // we should avoid processing of the signal about no more widgets attributes and
348 // do this after the restart operaion is finished if it was called
349 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
350 // if it should be called after restart
351 if (myIsFlagsBlocked) {
352 myNoMoreWidgetsAttribute = thePreviousAttributeID;
356 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
357 (myWorkshop->currentOperation());
358 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
361 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
362 if (aFOperation->isNeedToBeAborted()) {
363 aFOperation->abort();
366 bool isStarted = false;
367 if (!module()->sketchMgr()->sketchSolverError()) {
368 if (myRestartingMode != RM_Forbided) {
369 myRestartingMode = RM_LastFeatureUsed;
370 isStarted = startInternalEdit(thePreviousAttributeID);
374 aFOperation->commit();
379 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
386 // empty previous attribute means that the Apply/Ok button has focus and the enter
387 // should not lead to start edition mode of the previous operation
388 if (thePreviousAttributeID.empty())
391 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
392 (myWorkshop->currentOperation());
393 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
396 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
398 if (!isSketchSolverError) {
399 myRestartingMode = RM_EmptyFeatureUsed;
400 // It seems that the call is obsolete for Enter key processing
401 // It prevent finalysing of the current operation by Enter key
402 //isDone = startInternalEdit(thePreviousAttributeID);
408 void PartSet_SketcherReentrantMgr::onVertexSelected()
413 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
414 std::string anOperationId = anOperation->id().toStdString();
415 if (anOperationId == SketchPlugin_Line::ID() ||
416 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
417 /// If last line finished on vertex the lines creation sequence has to be break
418 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
419 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
420 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
421 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
422 bool aFoundWidget = false;
423 bool aFoundObligatory = false;
424 for (; anIt != aLast && !aFoundObligatory; anIt++) {
426 aFoundWidget = *anIt == anActiveWidget;
428 aFoundObligatory = (*anIt)->isObligatory();
430 if (!aFoundObligatory)
431 myRestartingMode = RM_Forbided;
435 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
438 if (isInternalEditActive()) {
439 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
440 (myWorkshop->currentOperation());
441 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
442 if (!aWidget->isModifiedInEdit().empty())
447 void PartSet_SketcherReentrantMgr::onBeforeStopped()
449 if (!isActiveMgr() || !myIsInternalEditOperation)
452 beforeStopInternalEdit();
455 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
457 return !isActiveMgr() || myRestartingMode == RM_None;
460 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
462 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
464 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
466 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
467 if (anActive) { // the manager is not active when the current operation is a usual Edit
468 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
469 (myWorkshop->currentOperation());
470 if (aFOperation->isEditOperation())
471 anActive = myIsInternalEditOperation;
477 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
480 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
484 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
485 /// event comes two times, so we should not start another internal edit operation
486 /// the Apply button becomes disabled becase the second additional internal feature is created
487 if (myIsInternalEditOperation)
490 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
491 (myWorkshop->currentOperation());
493 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
494 /// improvement to deselect automatically all eventual selected objects, when
495 // returning to the neutral point of the Sketcher or start internal edit
496 workshop()->selector()->clearSelection();
498 aFOperation->setEditOperation(true/*, false*/);
499 createInternalFeature();
501 myIsInternalEditOperation = true;
502 updateAcceptAllAction();
505 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
506 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
508 // activate selection filters of the first widget in the viewer
509 //onWidgetActivated();
511 // activate the last active widget in the Property Panel
512 if (!thePreviousAttributeID.empty()) {
513 ModuleBase_Operation* anEditOperation = module()->currentOperation();
514 if (anEditOperation) {
515 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
516 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
517 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
518 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
519 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
520 /// workaround for the same attributes used in different stacked widgets(attribute types)
521 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
523 aPreviousAttributeWidget = aWidgets[i];
526 // If the current widget is a selector, do nothing, it processes the mouse press
527 if (aPreviousAttributeWidget) {
528 if (!aPreviousAttributeWidget->isViewerSelector()) {
529 aPreviousAttributeWidget->focusTo();
530 aPreviousAttributeWidget->emitFocusInWidget();
531 aPreviousAttributeWidget->selectContent();
534 // in case of shape multi selector, the widget does not lose focus by filling
535 // like it is in shape selector. So, if enter is pressed, the multi shape selector
536 // control should be deactivated. The focus is moved to Apply button and there
537 // should not be active control visualized in property panel
538 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
539 aPanel->activateWidget(NULL, false);
541 // if there is no the next widget to be automatically activated,
542 // the Ok button in property
543 // panel should accept the focus(example is parallel constraint on sketch lines)
544 QToolButton* anOkBtn =
545 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
547 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
554 module()->sketchMgr()->clearClickedFlags();
559 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
561 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
562 (myWorkshop->currentOperation());
564 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
565 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
568 deleteInternalFeature();
571 void PartSet_SketcherReentrantMgr::restartOperation()
574 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
577 if (myIsInternalEditOperation) {
578 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
579 myWorkshop->currentOperation());
581 ModuleBase_ISelection* aSelection = myWorkshop->selection();
582 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
583 aSelection->getSelected(ModuleBase_ISelection::AllControls);
585 if (myInternalFeature.get())
586 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
587 module()->sketchMgr()->activeSketch());
589 myNoMoreWidgetsAttribute = "";
590 myIsFlagsBlocked = true;
591 /// launch has 'false' parameter to do not start new operation if the previous operation
592 /// is not committed. It is important for Line Sketch feature as it uses the previous
593 /// created feature parameter(to build coincidence), but by abort the previous is removed
594 module()->launchOperation(aFOperation->id(), true);
595 myIsFlagsBlocked = false;
598 // we should avoid processing of the signal about no more widgets attributes and
599 // do this after the restart operaion is finished if it was called
600 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
601 // if it should be called after restart
602 if (!myNoMoreWidgetsAttribute.empty()) {
603 onNoMoreWidgets(myNoMoreWidgetsAttribute);
604 myNoMoreWidgetsAttribute = "";
610 void PartSet_SketcherReentrantMgr::createInternalFeature()
612 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
613 (myWorkshop->currentOperation());
615 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
616 FeaturePtr anOperationFeature = aFOperation->feature();
618 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
619 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
622 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
623 << myInternalFeature->data()->name() << std::endl;
626 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
628 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
629 (aFOperation->propertyPanel());
631 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
632 myInternalWidget->setVisible(false);
634 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
636 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
637 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
639 aFactory.createWidget(anInternalPage);
640 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
642 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
643 bool isStoreValue = !aFOperation->isEditOperation() &&
644 !aWidget->getDefaultValue().empty() &&
645 !aWidget->isComputedDefault();
646 aWidget->setFeature(myInternalFeature, isStoreValue);
647 if (!isStoreValue && isFeatureChanged)
648 aWidget->restoreValue();
651 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
654 setInternalActiveWidget(aFirstWidget);
658 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
661 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
662 << myInternalFeature->data()->name() << std::endl;
664 setInternalActiveWidget(0);
665 delete myInternalWidget;
666 myInternalWidget = 0;
668 QObjectPtrList anObjects;
669 anObjects.append(myInternalFeature);
670 workshop()->deleteFeatures(anObjects);
671 myInternalFeature = FeaturePtr();
674 void PartSet_SketcherReentrantMgr::resetFlags()
676 if (!myIsFlagsBlocked) {
677 myIsInternalEditOperation = false;
678 updateAcceptAllAction();
679 myRestartingMode = RM_None;
680 myReentrantMessage = std::shared_ptr<Events_Message>();
684 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
685 const FeaturePtr& theNewFeature,
686 const CompositeFeaturePtr& theSketch,
687 const bool /*isTemporary*/)
689 bool aChanged = false;
690 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
691 !theSourceFeature->data()->isValid())
695 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
696 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
700 std::string aFeatureKind = theSourceFeature->getKind();
701 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
702 // Initialize new line with first point equal to end of previous
703 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
704 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
705 aSFData->attribute(SketchPlugin_Line::END_ID()));
706 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
707 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
708 aNFData->attribute(SketchPlugin_Line::START_ID()));
709 aNPoint->setValue(aSPoint->x(), aSPoint->y());
710 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
712 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
713 aSFData->attribute(SketchPlugin_Line::END_ID()));
714 aNPoint->setValue(aSPoint->x(), aSPoint->y());
716 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
718 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
719 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
720 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
721 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
722 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
723 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
726 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
728 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
729 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
730 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
731 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
732 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
733 //// if the arc is tangent, set coincidence to end point of the previous arc
734 //std::string anArcType = aSourceFeatureTypeAttr->value();
735 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
736 // // get the last point of the previuos arc feature(geom point 2d)
737 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
738 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
739 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
740 // aSData->attribute(SketchPlugin_Arc::END_ID()));
741 // // get point attribute on the current feature
742 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
743 // SketchPlugin_Arc::TANGENT_POINT_ID());
744 // aTangentPointAttr->setAttr(aSPointAttr);
746 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
747 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
748 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
749 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
752 //ModuleBase_Tools::flushUpdated(theNewFeature);
755 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
756 aFeatureKind == SketchPlugin_Split::ID()) {
757 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
758 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
759 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
760 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
761 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
762 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
763 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
764 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
765 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
766 theNewFeature->data()->attribute(aPreviewObjectAttribute));
767 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
768 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
769 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
770 theSourceFeature->data()->attribute(aPreviewPointAttribute));
771 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
772 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
773 theNewFeature->data()->attribute(aPreviewPointAttribute));
774 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
779 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
780 const CompositeFeaturePtr& /*theSketch*/) const
782 bool aTangentArc = false;
783 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
785 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
786 FeaturePtr aFeature = aFOperation->feature();
787 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
788 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
789 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
790 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
796 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
798 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
800 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
803 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
805 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
806 return aConnector->workshop();
809 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
811 return dynamic_cast<PartSet_Module*>(myWorkshop->module());
814 void PartSet_SketcherReentrantMgr::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
816 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
817 (myWorkshop->currentOperation());
820 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
821 (aFOperation->propertyPanel());
823 aPropertyPanel->setInternalActiveWidget(theWidget);