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_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"
46 #include "ModuleBase_ISelectionActivate.h"
48 #include <SketchPlugin_Feature.h>
49 #include <SketchPlugin_Line.h>
50 #include <SketchPlugin_MacroArc.h>
51 #include <SketchPlugin_MacroCircle.h>
52 #include <SketchPlugin_Point.h>
53 #include <SketchPlugin_Trim.h>
54 #include <SketchPlugin_Split.h>
56 #include <XGUI_Workshop.h>
57 #include <XGUI_ModuleConnector.h>
58 #include <XGUI_OperationMgr.h>
59 #include <XGUI_PropertyPanel.h>
60 #include <XGUI_ErrorMgr.h>
61 #include <XGUI_SelectionMgr.h>
63 #include <QToolButton>
65 //#define DEBUG_RESTART
67 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
68 : QObject(theWorkshop),
69 myWorkshop(theWorkshop),
70 myRestartingMode(RM_None),
71 myIsFlagsBlocked(false),
72 myIsInternalEditOperation(false),
73 myInternalActiveWidget(0),
74 myNoMoreWidgetsAttribute("")
78 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
82 ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
84 ModuleBase_ModelWidget* aWidget = 0;
88 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
90 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
91 if (aPanel) { // check for case when the operation is started but property panel is not filled
92 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
93 if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
94 aWidget = myInternalActiveWidget;
100 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
102 return myIsInternalEditOperation;
105 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
107 if (myIsInternalEditOperation) {
108 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
109 (myWorkshop->currentOperation());
111 FeaturePtr aFeature = aFOperation->feature();
112 QString anError = myWorkshop->module()->getFeatureError(aFeature);
113 // stop started internal edit operation as soon as the operation becomes invalid
114 // it is especially important for the sketch tangent arc feature
115 if (!anError.isEmpty()) {
116 aFOperation->setEditOperation(false);
117 //workshop()->operationMgr()->updateApplyOfOperations();
118 myIsInternalEditOperation = false;
119 updateAcceptAllAction();
125 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
127 bool aProcessed = false;
131 aProcessed = myIsInternalEditOperation;
137 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
142 //if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
143 //ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
144 // myWorkshop->currentOperation());
145 //CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
146 //if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
147 //copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
152 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
160 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
161 QMouseEvent* theEvent)
163 bool aProcessed = false;
167 if (myIsInternalEditOperation) {
168 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
169 (myWorkshop->currentOperation());
170 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
173 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
174 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
176 FeaturePtr aCurrentFeature = aFOperation->feature();
177 bool isLineFeature = false, isReentrantArcFeature = false;
178 std::string anAttributeOnStart;
179 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
180 anAttributeOnStart = SketchPlugin_Line::START_ID();
181 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
183 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
184 isReentrantArcFeature = true;
186 bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature;
187 if (aCanBeActivatedByMove) {
188 /// before restarting of operation we need to clear selection, as it may take part in
189 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
190 /// by mouse release when the operation was restarted.
191 workshop()->selector()->clearSelection();
193 myPreviousFeature = aFOperation->feature();
195 myPreviousFeature = FeaturePtr();
197 anActiveWidget = module()->activeWidget();
199 if (anActiveWidget && anActiveWidget->attributeID() == anAttributeOnStart) {
200 // it was not deactivated by preselection processing
201 aPanel->activateNextWidget(anActiveWidget);
204 // processing mouse move in active widget of restarted operation
205 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
206 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
208 aProcessor->mouseMoved(theWnd, theEvent);
215 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
216 QMouseEvent* /* theEvent*/)
218 return isActiveMgr() && myIsInternalEditOperation;
221 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
222 QMouseEvent* theEvent)
224 bool aProcessed = false;
228 if (myIsInternalEditOperation) {
229 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
230 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
232 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
233 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
235 // block of viewer update
236 // we need to block update content of the viewer because of Sketch Point feature
237 // in activate() the value of the point is initialized and it can be displayed
238 // but the default value is [0, 0]. So, we block update viewer contentent until
239 // onMouseRelease happens, which correct the point position
240 ModuleBase_Tools::blockUpdateViewer(true);
242 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
243 (myWorkshop->currentOperation());
244 myPreviousFeature = aFOperation->feature();
246 /// selection should be obtained from workshop before ask if the operation can be started as
247 /// the canStartOperation method performs commit/abort of previous operation.
248 /// Sometimes commit/abort
249 /// may cause selection clear(Sketch operation) as a result
250 /// it will be lost and is not used for preselection.
251 ModuleBase_ISelection* aSelection = myWorkshop->selection();
252 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
253 aSelection->getSelected(ModuleBase_ISelection::AllControls);
255 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
256 module()->sketchMgr()->activeSketch());
257 if (!aPreSelected.empty()) {
258 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
259 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
261 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
264 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
269 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
270 mySelectedObject = ObjectPtr();
271 mySelectedAttribute = AttributePtr();
273 myPreviousFeature = FeaturePtr();
276 // fill the first widget by the mouse event point
277 // if the active widget is not the first, it means that the restarted operation is filled by
278 // the current preselection.
279 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
280 module()->activeWidget());
281 //PartSet_WidgetPoint2D* aPoint2DWdg =
282 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
283 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
284 aPanel->findFirstAcceptingValueWidget());
285 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
286 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
287 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
288 if (!aPreSelected.empty())
289 aSelectedPrs = aPreSelected.front();
290 if (aSelectedPrs.get() && aSelectedPrs->object().get()
291 && !aSelectedPrs->object()->data()->isValid()) {
292 // the selected object was removed diring restart, e.g. presentable macro feature
293 // there are created objects to replace the object depending on created feature kind
294 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
296 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
297 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
298 //if (!aPreSelected.empty())
299 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
301 // unblock viewer update
302 ModuleBase_Tools::blockUpdateViewer(false);
308 //******************************************************
309 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
310 const std::shared_ptr<Events_Message>& theMessage)
312 ReentrantMessagePtr aReentrantMessage =
313 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
314 if (!aReentrantMessage.get())
317 // if feature has already filled the selected object, we should not overwrite it
318 if (!aReentrantMessage->selectedObject().get())
319 aReentrantMessage->setSelectedObject(mySelectedObject);
321 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
322 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
325 //void PartSet_SketcherReentrantMgr::onWidgetActivated()
327 // if (!isActiveMgr())
329 // if (!myIsInternalEditOperation)
332 // PartSet_Module* aModule = module();
333 // ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
334 // ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
335 // if (aFirstWidget != aPanel->activeWidget()) {
336 // ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
339 // myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
344 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
347 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
353 // we should avoid processing of the signal about no more widgets attributes and
354 // do this after the restart operaion is finished if it was called
355 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
356 // if it should be called after restart
357 if (myIsFlagsBlocked) {
358 myNoMoreWidgetsAttribute = thePreviousAttributeID;
362 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
363 (myWorkshop->currentOperation());
364 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
367 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
368 if (aFOperation->isNeedToBeAborted()) {
369 aFOperation->abort();
372 bool isStarted = false;
373 if (!module()->sketchMgr()->sketchSolverError()) {
374 if (myRestartingMode != RM_Forbided) {
375 myRestartingMode = RM_LastFeatureUsed;
376 isStarted = startInternalEdit(thePreviousAttributeID);
380 aFOperation->commit();
385 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
392 // empty previous attribute means that the Apply/Ok button has focus and the enter
393 // should not lead to start edition mode of the previous operation
394 if (thePreviousAttributeID.empty())
397 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
398 (myWorkshop->currentOperation());
399 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
402 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
404 if (!isSketchSolverError) {
405 myRestartingMode = RM_EmptyFeatureUsed;
406 isDone = startInternalEdit(thePreviousAttributeID);
412 void PartSet_SketcherReentrantMgr::onVertexSelected()
417 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
418 std::string anOperationId = anOperation->id().toStdString();
419 if (anOperationId == SketchPlugin_Line::ID() ||
420 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
421 /// If last line finished on vertex the lines creation sequence has to be break
422 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
423 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
424 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
425 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
426 bool aFoundWidget = false;
427 bool aFoundObligatory = false;
428 for (; anIt != aLast && !aFoundObligatory; anIt++) {
430 aFoundWidget = *anIt == anActiveWidget;
432 aFoundObligatory = (*anIt)->isObligatory();
434 if (!aFoundObligatory)
435 myRestartingMode = RM_Forbided;
439 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
442 if (isInternalEditActive()) {
443 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
444 (myWorkshop->currentOperation());
445 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
446 if (!aWidget->isModifiedInEdit().empty())
451 void PartSet_SketcherReentrantMgr::onBeforeStopped()
453 if (!isActiveMgr() || !myIsInternalEditOperation)
456 beforeStopInternalEdit();
459 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
461 return !isActiveMgr() || myRestartingMode == RM_None;
464 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
466 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
468 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
470 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
471 if (anActive) { // the manager is not active when the current operation is a usual Edit
472 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
473 (myWorkshop->currentOperation());
474 if (aFOperation->isEditOperation())
475 anActive = myIsInternalEditOperation;
481 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
484 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
488 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
489 /// event comes two times, so we should not start another internal edit operation
490 /// the Apply button becomes disabled becase the second additional internal feature is created
491 if (myIsInternalEditOperation)
494 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
495 (myWorkshop->currentOperation());
497 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
498 /// improvement to deselect automatically all eventual selected objects, when
499 // returning to the neutral point of the Sketcher or start internal edit
500 workshop()->selector()->clearSelection();
502 aFOperation->setEditOperation(true/*, false*/);
503 createInternalFeature();
505 myIsInternalEditOperation = true;
506 updateAcceptAllAction();
509 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
510 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
512 // activate selection filters of the first widget in the viewer
513 //onWidgetActivated();
515 // activate the last active widget in the Property Panel
516 if (!thePreviousAttributeID.empty()) {
517 ModuleBase_Operation* anEditOperation = module()->currentOperation();
518 if (anEditOperation) {
519 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
520 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
521 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
522 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
523 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
524 /// workaround for the same attributes used in different stacked widgets(attribute types)
525 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
527 aPreviousAttributeWidget = aWidgets[i];
530 // If the current widget is a selector, do nothing, it processes the mouse press
531 if (aPreviousAttributeWidget) {
532 if (!aPreviousAttributeWidget->isViewerSelector()) {
533 aPreviousAttributeWidget->focusTo();
534 aPreviousAttributeWidget->emitFocusInWidget();
535 aPreviousAttributeWidget->selectContent();
538 // in case of shape multi selector, the widget does not lose focus by filling
539 // like it is in shape selector. So, if enter is pressed, the multi shape selector
540 // control should be deactivated. The focus is moved to Apply button and there
541 // should not be active control visualized in property panel
542 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
543 aPanel->activateWidget(NULL, false);
545 // if there is no the next widget to be automatically activated,
546 // the Ok button in property
547 // panel should accept the focus(example is parallel constraint on sketch lines)
548 QToolButton* anOkBtn =
549 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
551 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
558 module()->sketchMgr()->clearClickedFlags();
563 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
565 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
566 (myWorkshop->currentOperation());
568 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
569 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
572 deleteInternalFeature();
575 void PartSet_SketcherReentrantMgr::restartOperation()
578 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
581 if (myIsInternalEditOperation) {
582 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
583 myWorkshop->currentOperation());
585 ModuleBase_ISelection* aSelection = myWorkshop->selection();
586 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
587 aSelection->getSelected(ModuleBase_ISelection::AllControls);
589 if (myInternalFeature.get())
590 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
591 module()->sketchMgr()->activeSketch());
593 myNoMoreWidgetsAttribute = "";
594 myIsFlagsBlocked = true;
595 /// launch has 'false' parameter to do not start new operation if the previous operation
596 /// is not committed. It is important for Line Sketch feature as it uses the previous
597 /// created feature parameter(to build coincidence), but by abort the previous is removed
598 module()->launchOperation(aFOperation->id(), true);
599 myIsFlagsBlocked = false;
602 // we should avoid processing of the signal about no more widgets attributes and
603 // do this after the restart operaion is finished if it was called
604 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
605 // if it should be called after restart
606 if (!myNoMoreWidgetsAttribute.empty()) {
607 onNoMoreWidgets(myNoMoreWidgetsAttribute);
608 myNoMoreWidgetsAttribute = "";
614 void PartSet_SketcherReentrantMgr::createInternalFeature()
616 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
617 (myWorkshop->currentOperation());
619 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
620 FeaturePtr anOperationFeature = aFOperation->feature();
622 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
623 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
626 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
627 << myInternalFeature->data()->name() << std::endl;
630 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
632 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
633 (aFOperation->propertyPanel());
635 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
636 myInternalWidget->setVisible(false);
638 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
640 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
641 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
643 aFactory.createWidget(anInternalPage);
644 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
646 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
647 bool isStoreValue = !aFOperation->isEditOperation() &&
648 !aWidget->getDefaultValue().empty() &&
649 !aWidget->isComputedDefault();
650 aWidget->setFeature(myInternalFeature, isStoreValue);
651 if (!isStoreValue && isFeatureChanged)
652 aWidget->restoreValue();
655 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
658 myInternalActiveWidget = aFirstWidget;
662 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
665 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
666 << myInternalFeature->data()->name() << std::endl;
668 if (myInternalActiveWidget)
669 myInternalActiveWidget = 0;
670 delete myInternalWidget;
671 myInternalWidget = 0;
673 QObjectPtrList anObjects;
674 anObjects.append(myInternalFeature);
675 workshop()->deleteFeatures(anObjects);
676 myInternalFeature = FeaturePtr();
679 void PartSet_SketcherReentrantMgr::resetFlags()
681 if (!myIsFlagsBlocked) {
682 myIsInternalEditOperation = false;
683 updateAcceptAllAction();
684 myRestartingMode = RM_None;
685 myReentrantMessage = std::shared_ptr<Events_Message>();
689 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
690 const FeaturePtr& theNewFeature,
691 const CompositeFeaturePtr& theSketch,
692 const bool /*isTemporary*/)
694 bool aChanged = false;
695 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
696 !theSourceFeature->data()->isValid())
700 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
701 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
705 std::string aFeatureKind = theSourceFeature->getKind();
706 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
707 // Initialize new line with first point equal to end of previous
708 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
709 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
710 aSFData->attribute(SketchPlugin_Line::END_ID()));
711 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
712 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
713 aNFData->attribute(SketchPlugin_Line::START_ID()));
714 aNPoint->setValue(aSPoint->x(), aSPoint->y());
715 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
717 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
718 aSFData->attribute(SketchPlugin_Line::END_ID()));
719 aNPoint->setValue(aSPoint->x(), aSPoint->y());
721 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
723 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
724 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
725 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
726 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
727 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
728 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
731 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
733 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
734 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
735 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
736 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
737 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
738 //// if the arc is tangent, set coincidence to end point of the previous arc
739 //std::string anArcType = aSourceFeatureTypeAttr->value();
740 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
741 // // get the last point of the previuos arc feature(geom point 2d)
742 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
743 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
744 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
745 // aSData->attribute(SketchPlugin_Arc::END_ID()));
746 // // get point attribute on the current feature
747 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
748 // SketchPlugin_Arc::TANGENT_POINT_ID());
749 // aTangentPointAttr->setAttr(aSPointAttr);
751 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
752 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
753 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
754 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
757 //ModuleBase_Tools::flushUpdated(theNewFeature);
760 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
761 aFeatureKind == SketchPlugin_Split::ID()) {
762 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
763 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
764 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
765 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
766 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
767 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
768 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
769 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
770 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
771 theNewFeature->data()->attribute(aPreviewObjectAttribute));
772 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
773 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
774 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
775 theSourceFeature->data()->attribute(aPreviewPointAttribute));
776 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
777 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
778 theNewFeature->data()->attribute(aPreviewPointAttribute));
779 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
784 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
785 const CompositeFeaturePtr& /*theSketch*/) const
787 bool aTangentArc = false;
788 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
790 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
791 FeaturePtr aFeature = aFOperation->feature();
792 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
793 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
794 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
795 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
801 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
803 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
805 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
808 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
810 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
811 return aConnector->workshop();
814 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
816 return dynamic_cast<PartSet_Module*>(myWorkshop->module());