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 aFOperation->setEditOperation(true/*, false*/);
490 createInternalFeature();
492 myIsInternalEditOperation = true;
493 updateAcceptAllAction();
496 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
497 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
499 // activate selection filters of the first widget in the viewer
502 // activate the last active widget in the Property Panel
503 if (!thePreviousAttributeID.empty()) {
504 ModuleBase_Operation* anEditOperation = module()->currentOperation();
505 if (anEditOperation) {
506 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
507 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
508 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
509 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
510 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
511 /// workaround for the same attributes used in different stacked widgets(attribute types)
512 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
514 aPreviousAttributeWidget = aWidgets[i];
517 // If the current widget is a selector, do nothing, it processes the mouse press
518 if (aPreviousAttributeWidget) {
519 if (!aPreviousAttributeWidget->isViewerSelector()) {
520 aPreviousAttributeWidget->focusTo();
521 aPreviousAttributeWidget->emitFocusInWidget();
522 aPreviousAttributeWidget->selectContent();
525 // in case of shape multi selector, the widget does not lose focus by filling
526 // like it is in shape selector. So, if enter is pressed, the multi shape selector
527 // control should be deactivated. The focus is moved to Apply button and there
528 // should not be active control visualized in property panel
529 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
530 aPanel->activateWidget(NULL, false);
532 // if there is no the next widget to be automatically activated,
533 // the Ok button in property
534 // panel should accept the focus(example is parallel constraint on sketch lines)
535 QToolButton* anOkBtn =
536 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
538 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
545 module()->sketchMgr()->clearClickedFlags();
550 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
552 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
553 (myWorkshop->currentOperation());
555 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
556 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
559 deleteInternalFeature();
562 void PartSet_SketcherReentrantMgr::restartOperation()
565 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
568 if (myIsInternalEditOperation) {
569 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
570 myWorkshop->currentOperation());
572 ModuleBase_ISelection* aSelection = myWorkshop->selection();
573 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
574 aSelection->getSelected(ModuleBase_ISelection::AllControls);
576 if (myInternalFeature.get())
577 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
578 module()->sketchMgr()->activeSketch());
580 myNoMoreWidgetsAttribute = "";
581 myIsFlagsBlocked = true;
582 /// launch has 'false' parameter to do not start new operation if the previous operation
583 /// is not committed. It is important for Line Sketch feature as it uses the previous
584 /// created feature parameter(to build coincidence), but by abort the previous is removed
585 module()->launchOperation(aFOperation->id(), true);
586 myIsFlagsBlocked = false;
589 // we should avoid processing of the signal about no more widgets attributes and
590 // do this after the restart operaion is finished if it was called
591 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
592 // if it should be called after restart
593 if (!myNoMoreWidgetsAttribute.empty()) {
594 onNoMoreWidgets(myNoMoreWidgetsAttribute);
595 myNoMoreWidgetsAttribute = "";
601 void PartSet_SketcherReentrantMgr::createInternalFeature()
603 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
604 (myWorkshop->currentOperation());
606 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
607 FeaturePtr anOperationFeature = aFOperation->feature();
609 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
610 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
613 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
614 << myInternalFeature->data()->name() << std::endl;
617 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
619 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
620 (aFOperation->propertyPanel());
622 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
623 myInternalWidget->setVisible(false);
625 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
627 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
628 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
630 aFactory.createWidget(anInternalPage);
631 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
633 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
634 bool isStoreValue = !aFOperation->isEditOperation() &&
635 !aWidget->getDefaultValue().empty() &&
636 !aWidget->isComputedDefault();
637 aWidget->setFeature(myInternalFeature, isStoreValue);
638 if (!isStoreValue && isFeatureChanged)
639 aWidget->restoreValue();
642 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
645 myInternalActiveWidget = aFirstWidget;
649 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
652 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
653 << myInternalFeature->data()->name() << std::endl;
655 if (myInternalActiveWidget) {
656 ModuleBase_WidgetSelector* aWSelector =
657 dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
659 aWSelector->activateSelectionAndFilters(false);
660 myInternalActiveWidget = 0;
662 delete myInternalWidget;
663 myInternalWidget = 0;
665 QObjectPtrList anObjects;
666 anObjects.append(myInternalFeature);
667 workshop()->deleteFeatures(anObjects);
668 myInternalFeature = FeaturePtr();
671 void PartSet_SketcherReentrantMgr::resetFlags()
673 if (!myIsFlagsBlocked) {
674 myIsInternalEditOperation = false;
675 updateAcceptAllAction();
676 myRestartingMode = RM_None;
677 myReentrantMessage = std::shared_ptr<Events_Message>();
681 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
682 const FeaturePtr& theNewFeature,
683 const CompositeFeaturePtr& theSketch,
684 const bool /*isTemporary*/)
686 bool aChanged = false;
687 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
688 !theSourceFeature->data()->isValid())
692 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
693 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
697 std::string aFeatureKind = theSourceFeature->getKind();
698 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
699 // Initialize new line with first point equal to end of previous
700 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
701 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
702 aSFData->attribute(SketchPlugin_Line::END_ID()));
703 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
704 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
705 aNFData->attribute(SketchPlugin_Line::START_ID()));
706 aNPoint->setValue(aSPoint->x(), aSPoint->y());
707 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
709 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
710 aSFData->attribute(SketchPlugin_Line::END_ID()));
711 aNPoint->setValue(aSPoint->x(), aSPoint->y());
713 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
715 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
716 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
717 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
718 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
719 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
720 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
723 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
725 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
726 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
727 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
728 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
729 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
730 //// if the arc is tangent, set coincidence to end point of the previous arc
731 //std::string anArcType = aSourceFeatureTypeAttr->value();
732 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
733 // // get the last point of the previuos arc feature(geom point 2d)
734 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
735 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
736 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
737 // aSData->attribute(SketchPlugin_Arc::END_ID()));
738 // // get point attribute on the current feature
739 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
740 // SketchPlugin_Arc::TANGENT_POINT_ID());
741 // aTangentPointAttr->setAttr(aSPointAttr);
743 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
744 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
745 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
746 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
749 //ModuleBase_Tools::flushUpdated(theNewFeature);
752 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
753 aFeatureKind == SketchPlugin_Split::ID()) {
754 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
755 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
756 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
757 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
758 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
759 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
760 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
761 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
762 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
763 theNewFeature->data()->attribute(aPreviewObjectAttribute));
764 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
765 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
766 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
767 theSourceFeature->data()->attribute(aPreviewPointAttribute));
768 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
769 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
770 theNewFeature->data()->attribute(aPreviewPointAttribute));
771 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
776 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
777 const CompositeFeaturePtr& /*theSketch*/) const
779 bool aTangentArc = false;
780 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
782 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
783 FeaturePtr aFeature = aFOperation->feature();
784 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
785 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
786 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
787 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
793 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
795 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
797 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
800 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
802 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
803 return aConnector->workshop();
806 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
808 return dynamic_cast<PartSet_Module*>(myWorkshop->module());