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 "GeomAPI_Lin2d.h"
35 #include "GeomAPI_Dir2d.h"
37 #include <ModuleBase_IPropertyPanel.h>
38 #include <ModuleBase_ISelectionActivate.h>
39 #include <ModuleBase_OperationFeature.h>
40 #include <ModuleBase_ModelWidget.h>
41 #include <ModuleBase_ViewerPrs.h>
42 #include <ModuleBase_WidgetSelector.h>
43 #include <ModuleBase_PageWidget.h>
44 #include <ModuleBase_PageBase.h>
45 #include <ModuleBase_WidgetFactory.h>
46 #include <ModuleBase_OperationDescription.h>
47 #include "ModuleBase_ToolBox.h"
48 #include "ModuleBase_ISelection.h"
50 #include <SketchPlugin_Feature.h>
51 #include <SketchPlugin_Line.h>
52 #include <SketchPlugin_MacroArc.h>
53 #include <SketchPlugin_MacroCircle.h>
54 #include <SketchPlugin_Point.h>
55 #include <SketchPlugin_Trim.h>
56 #include <SketchPlugin_Split.h>
57 #include <SketchPlugin_ConstraintHorizontal.h>
58 #include <SketchPlugin_ConstraintVertical.h>
60 #include <XGUI_Workshop.h>
61 #include <XGUI_ModuleConnector.h>
62 #include <XGUI_OperationMgr.h>
63 #include <XGUI_PropertyPanel.h>
64 #include <XGUI_ErrorMgr.h>
65 #include <XGUI_SelectionMgr.h>
67 #include <QToolButton>
69 //#define DEBUG_RESTART
71 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
72 : QObject(theWorkshop),
73 myWorkshop(theWorkshop),
74 myRestartingMode(RM_None),
75 myIsFlagsBlocked(false),
76 myIsInternalEditOperation(false),
77 myNoMoreWidgetsAttribute(""),
78 myIsAutoConstraints(true)
82 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
86 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
88 return myIsInternalEditOperation;
91 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
93 if (myIsInternalEditOperation) {
94 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
95 (myWorkshop->currentOperation());
97 FeaturePtr aFeature = aFOperation->feature();
98 QString anError = myWorkshop->module()->getFeatureError(aFeature);
99 // stop started internal edit operation as soon as the operation becomes invalid
100 // it is especially important for the sketch tangent arc feature
101 if (!anError.isEmpty()) {
102 aFOperation->setEditOperation(false);
103 //workshop()->operationMgr()->updateApplyOfOperations();
104 myIsInternalEditOperation = false;
105 updateAcceptAllAction();
111 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
113 bool aProcessed = false;
117 aProcessed = myIsInternalEditOperation;
123 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
128 //if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
129 //ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
130 // myWorkshop->currentOperation());
131 //CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
132 //if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
133 //copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
138 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
146 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
147 QMouseEvent* theEvent)
149 bool aProcessed = false;
153 if (myIsInternalEditOperation) {
154 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
155 (myWorkshop->currentOperation());
156 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
159 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
160 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
162 FeaturePtr aCurrentFeature = aFOperation->feature();
163 bool isLineFeature = false, isReentrantArcFeature = false;
164 std::string anAttributeOnStart;
165 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
166 anAttributeOnStart = SketchPlugin_Line::START_ID();
167 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
169 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
170 isReentrantArcFeature = true;
172 bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature;
173 if (aCanBeActivatedByMove) {
174 /// before restarting of operation we need to clear selection, as it may take part in
175 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
176 /// by mouse release when the operation was restarted.
177 workshop()->selector()->clearSelection();
179 myPreviousFeature = aFOperation->feature();
181 myPreviousFeature = FeaturePtr();
183 anActiveWidget = module()->activeWidget();
185 if (anActiveWidget && anActiveWidget->attributeID() == anAttributeOnStart) {
186 // it was not deactivated by preselection processing
187 aPanel->activateNextWidget(anActiveWidget);
190 // processing mouse move in active widget of restarted operation
191 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
192 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
194 aProcessor->mouseMoved(theWnd, theEvent);
201 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
202 QMouseEvent* /* theEvent*/)
204 return isActiveMgr() && myIsInternalEditOperation;
207 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
208 QMouseEvent* theEvent)
210 bool aProcessed = false;
214 if (myIsInternalEditOperation) {
215 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
216 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
218 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
219 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
221 // block of viewer update
222 // we need to block update content of the viewer because of Sketch Point feature
223 // in activate() the value of the point is initialized and it can be displayed
224 // but the default value is [0, 0]. So, we block update viewer contentent until
225 // onMouseRelease happens, which correct the point position
226 ModuleBase_Tools::blockUpdateViewer(true);
228 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
229 (myWorkshop->currentOperation());
230 myPreviousFeature = aFOperation->feature();
232 /// selection should be obtained from workshop before ask if the operation can be started as
233 /// the canStartOperation method performs commit/abort of previous operation.
234 /// Sometimes commit/abort
235 /// may cause selection clear(Sketch operation) as a result
236 /// it will be lost and is not used for preselection.
237 ModuleBase_ISelection* aSelection = myWorkshop->selection();
238 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
239 aSelection->getSelected(ModuleBase_ISelection::AllControls);
241 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
242 module()->sketchMgr()->activeSketch());
243 FeaturePtr anExternalCreatedFeature;
244 if (!aPreSelected.empty()) {
245 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
246 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
248 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
251 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
252 ObjectPtr anExternalObject =
253 aPointWidget->getExternalObjectMgr()->getExternalObjectValidated();
254 // if external object is during reentrant operation and is used as a parameter of feature
255 // it should be removed after the operation is restarted. (Circle feature, Projection)
256 if (anExternalObject.get())
257 anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject);
262 // remove created external feature
263 if (anExternalCreatedFeature.get()) {
264 QObjectPtrList anObjects;
265 anObjects.append(anExternalCreatedFeature);
266 workshop()->deleteFeatures(anObjects);
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 if (myIsAutoConstraints)
381 addConstraints(aFOperation->feature());
382 aFOperation->commit();
388 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
395 // empty previous attribute means that the Apply/Ok button has focus and the enter
396 // should not lead to start edition mode of the previous operation
397 if (thePreviousAttributeID.empty())
400 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
401 (myWorkshop->currentOperation());
402 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
405 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
407 if (!isSketchSolverError) {
408 myRestartingMode = RM_EmptyFeatureUsed;
409 // It seems that the call is obsolete for Enter key processing
410 // It prevent finalysing of the current operation by Enter key
411 //isDone = startInternalEdit(thePreviousAttributeID);
417 void PartSet_SketcherReentrantMgr::onVertexSelected()
422 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
423 std::string anOperationId = anOperation->id().toStdString();
424 if (anOperationId == SketchPlugin_Line::ID() ||
425 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
426 /// If last line finished on vertex the lines creation sequence has to be break
427 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
428 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
429 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
430 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
431 bool aFoundWidget = false;
432 bool aFoundObligatory = false;
433 for (; anIt != aLast && !aFoundObligatory; anIt++) {
435 aFoundWidget = *anIt == anActiveWidget;
437 aFoundObligatory = (*anIt)->isObligatory();
439 if (!aFoundObligatory)
440 myRestartingMode = RM_Forbided;
444 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
447 if (isInternalEditActive()) {
448 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
449 (myWorkshop->currentOperation());
450 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
451 if (!aWidget->isModifiedInEdit().empty())
456 void PartSet_SketcherReentrantMgr::onBeforeStopped()
458 if (!isActiveMgr() || !myIsInternalEditOperation)
461 beforeStopInternalEdit();
464 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
466 return !isActiveMgr() || myRestartingMode == RM_None;
469 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
471 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
473 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
475 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
476 if (anActive) { // the manager is not active when the current operation is a usual Edit
477 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
478 (myWorkshop->currentOperation());
479 if (aFOperation->isEditOperation())
480 anActive = myIsInternalEditOperation;
486 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
489 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
493 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
494 /// event comes two times, so we should not start another internal edit operation
495 /// the Apply button becomes disabled becase the second additional internal feature is created
496 if (myIsInternalEditOperation)
499 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
500 (myWorkshop->currentOperation());
502 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
503 /// improvement to deselect automatically all eventual selected objects, when
504 // returning to the neutral point of the Sketcher or start internal edit
505 workshop()->selector()->clearSelection();
507 if (myIsAutoConstraints)
508 addConstraints(aFOperation->feature());
510 aFOperation->setEditOperation(true/*, false*/);
511 createInternalFeature();
513 myIsInternalEditOperation = true;
514 updateAcceptAllAction();
517 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
518 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
520 // activate selection filters of the first widget in the viewer
521 //onWidgetActivated();
523 // activate the last active widget in the Property Panel
524 if (!thePreviousAttributeID.empty()) {
525 ModuleBase_Operation* anEditOperation = module()->currentOperation();
526 if (anEditOperation) {
527 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
528 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
529 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
530 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
531 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
532 /// workaround for the same attributes used in different stacked widgets(attribute types)
533 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
535 aPreviousAttributeWidget = aWidgets[i];
538 // If the current widget is a selector, do nothing, it processes the mouse press
539 if (aPreviousAttributeWidget) {
540 if (!aPreviousAttributeWidget->isViewerSelector()) {
541 aPreviousAttributeWidget->focusTo();
542 aPreviousAttributeWidget->emitFocusInWidget();
543 aPreviousAttributeWidget->selectContent();
546 // in case of shape multi selector, the widget does not lose focus by filling
547 // like it is in shape selector. So, if enter is pressed, the multi shape selector
548 // control should be deactivated. The focus is moved to Apply button and there
549 // should not be active control visualized in property panel
550 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
551 aPanel->activateWidget(NULL, false);
553 // if there is no the next widget to be automatically activated,
554 // the Ok button in property
555 // panel should accept the focus(example is parallel constraint on sketch lines)
556 QToolButton* anOkBtn =
557 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
559 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
566 module()->sketchMgr()->clearClickedFlags();
571 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
573 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
574 (myWorkshop->currentOperation());
576 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
577 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
580 deleteInternalFeature();
583 void PartSet_SketcherReentrantMgr::restartOperation()
586 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
589 if (myIsInternalEditOperation) {
590 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
591 myWorkshop->currentOperation());
593 ModuleBase_ISelection* aSelection = myWorkshop->selection();
594 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
595 aSelection->getSelected(ModuleBase_ISelection::AllControls);
597 if (myInternalFeature.get())
598 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
599 module()->sketchMgr()->activeSketch());
601 myNoMoreWidgetsAttribute = "";
602 myIsFlagsBlocked = true;
603 /// launch has 'false' parameter to do not start new operation if the previous operation
604 /// is not committed. It is important for Line Sketch feature as it uses the previous
605 /// created feature parameter(to build coincidence), but by abort the previous is removed
606 module()->launchOperation(aFOperation->id(), true);
607 myIsFlagsBlocked = false;
610 // we should avoid processing of the signal about no more widgets attributes and
611 // do this after the restart operaion is finished if it was called
612 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
613 // if it should be called after restart
614 if (!myNoMoreWidgetsAttribute.empty()) {
615 onNoMoreWidgets(myNoMoreWidgetsAttribute);
616 myNoMoreWidgetsAttribute = "";
622 void PartSet_SketcherReentrantMgr::createInternalFeature()
624 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
625 (myWorkshop->currentOperation());
627 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
628 FeaturePtr anOperationFeature = aFOperation->feature();
630 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
631 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
634 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
635 << myInternalFeature->data()->name() << std::endl;
638 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
640 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
641 (aFOperation->propertyPanel());
643 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
644 myInternalWidget->setVisible(false);
646 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
648 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
649 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
651 aFactory.createWidget(anInternalPage);
652 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
654 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
655 bool isStoreValue = !aFOperation->isEditOperation() &&
656 !aWidget->getDefaultValue().empty() &&
657 !aWidget->isComputedDefault();
658 aWidget->setFeature(myInternalFeature, isStoreValue);
659 if (!isStoreValue && isFeatureChanged)
660 aWidget->restoreValue();
663 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
666 setInternalActiveWidget(aFirstWidget);
670 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
673 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
674 << myInternalFeature->data()->name() << std::endl;
676 setInternalActiveWidget(0);
677 delete myInternalWidget;
678 myInternalWidget = 0;
680 QObjectPtrList anObjects;
681 anObjects.append(myInternalFeature);
682 workshop()->deleteFeatures(anObjects);
683 myInternalFeature = FeaturePtr();
686 void PartSet_SketcherReentrantMgr::resetFlags()
688 if (!myIsFlagsBlocked) {
689 myIsInternalEditOperation = false;
690 updateAcceptAllAction();
691 myRestartingMode = RM_None;
692 myReentrantMessage = std::shared_ptr<Events_Message>();
696 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
697 const FeaturePtr& theNewFeature,
698 const CompositeFeaturePtr& theSketch,
699 const bool /*isTemporary*/)
701 bool aChanged = false;
702 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
703 !theSourceFeature->data()->isValid())
707 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
708 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
712 std::string aFeatureKind = theSourceFeature->getKind();
713 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
714 // Initialize new line with first point equal to end of previous
715 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
716 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
717 aSFData->attribute(SketchPlugin_Line::END_ID()));
718 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
719 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
720 aNFData->attribute(SketchPlugin_Line::START_ID()));
721 aNPoint->setValue(aSPoint->x(), aSPoint->y());
722 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
724 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
725 aSFData->attribute(SketchPlugin_Line::END_ID()));
726 aNPoint->setValue(aSPoint->x(), aSPoint->y());
728 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
730 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
731 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
732 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
733 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
734 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
735 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
738 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
740 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
741 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
742 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
743 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
744 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
745 //// if the arc is tangent, set coincidence to end point of the previous arc
746 //std::string anArcType = aSourceFeatureTypeAttr->value();
747 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
748 // // get the last point of the previuos arc feature(geom point 2d)
749 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
750 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
751 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
752 // aSData->attribute(SketchPlugin_Arc::END_ID()));
753 // // get point attribute on the current feature
754 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
755 // SketchPlugin_Arc::TANGENT_POINT_ID());
756 // aTangentPointAttr->setAttr(aSPointAttr);
758 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
759 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
760 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
761 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
764 //ModuleBase_Tools::flushUpdated(theNewFeature);
767 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
768 aFeatureKind == SketchPlugin_Split::ID()) {
769 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
770 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
771 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
772 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
773 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
774 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
775 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
776 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
777 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
778 theNewFeature->data()->attribute(aPreviewObjectAttribute));
779 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
780 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
781 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
782 theSourceFeature->data()->attribute(aPreviewPointAttribute));
783 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
784 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
785 theNewFeature->data()->attribute(aPreviewPointAttribute));
786 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
791 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
792 const CompositeFeaturePtr& /*theSketch*/) const
794 bool aTangentArc = false;
795 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
797 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
798 FeaturePtr aFeature = aFOperation->feature();
799 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
800 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
801 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
802 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
808 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
810 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
812 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
815 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
817 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
818 return aConnector->workshop();
821 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
823 return dynamic_cast<PartSet_Module*>(myWorkshop->module());
826 void PartSet_SketcherReentrantMgr::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
828 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
829 (myWorkshop->currentOperation());
832 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
833 (aFOperation->propertyPanel());
835 aPropertyPanel->setInternalActiveWidget(theWidget);
839 void PartSet_SketcherReentrantMgr::onAutoConstraints(bool isOn)
841 myIsAutoConstraints = isOn;
844 void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature)
846 if (theFeature->getKind() != SketchPlugin_Line::ID())
849 static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0));
850 static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1));
852 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
853 std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
854 aData->attribute(SketchPlugin_Line::START_ID()));
855 std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
856 aData->attribute(SketchPlugin_Line::END_ID()));
857 if (aPoint1.get() && aPoint2.get()) {
858 GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPoint1->pnt(), aPoint2->pnt()));
859 GeomDir2dPtr aDir = aLine->direction();
860 double aHorAngle = fabs(myHorDir->angle(aDir));
861 double aVertAngle = fabs(myVertDir->angle(aDir));
862 if (aHorAngle > M_PI/2.)
863 aHorAngle = M_PI - aHorAngle;
864 if (aVertAngle > M_PI/2.)
865 aVertAngle = M_PI - aVertAngle;
867 double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
868 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
870 if (aHorAngle < aTolerance)
871 // Add horizontal constraint
872 aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
873 else if (aVertAngle < aTolerance)
874 // Add vertical constraint
875 aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID());
877 if (aFeature.get()) {
878 aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(
879 theFeature->firstResult());