1 // Copyright (C) 2014-2020 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),
79 myLastAutoConstraint(0)
83 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
87 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
89 return myIsInternalEditOperation;
92 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
94 if (myIsInternalEditOperation) {
95 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
96 (myWorkshop->currentOperation());
98 FeaturePtr aFeature = aFOperation->feature();
99 QString anError = myWorkshop->module()->getFeatureError(aFeature);
100 // stop started internal edit operation as soon as the operation becomes invalid
101 // it is especially important for the sketch tangent arc feature
102 if (!anError.isEmpty()) {
103 aFOperation->setEditOperation(false);
104 //workshop()->operationMgr()->updateApplyOfOperations();
105 myIsInternalEditOperation = false;
106 updateAcceptAllAction();
112 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
114 bool aProcessed = false;
118 aProcessed = myIsInternalEditOperation;
124 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
129 //if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
130 //ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
131 // myWorkshop->currentOperation());
132 //CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
133 //if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
134 //copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
139 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
147 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
148 QMouseEvent* theEvent)
150 bool aProcessed = false;
154 if (myIsInternalEditOperation) {
155 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
156 (myWorkshop->currentOperation());
157 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
160 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
161 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
163 FeaturePtr aCurrentFeature = aFOperation->feature();
164 bool isLineFeature = false, isReentrantArcFeature = false;
165 std::string anAttributeOnStart;
166 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
167 anAttributeOnStart = SketchPlugin_Line::START_ID();
168 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
170 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
171 isReentrantArcFeature = true;
173 bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature;
174 if (aCanBeActivatedByMove) {
175 /// before restarting of operation we need to clear selection, as it may take part in
176 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
177 /// by mouse release when the operation was restarted.
178 workshop()->selector()->clearSelection();
180 myPreviousFeature = aFOperation->feature();
182 myPreviousFeature = FeaturePtr();
184 anActiveWidget = module()->activeWidget();
186 if (anActiveWidget && anActiveWidget->attributeID() == anAttributeOnStart) {
187 // it was not deactivated by preselection processing
188 aPanel->activateNextWidget(anActiveWidget);
191 // processing mouse move in active widget of restarted operation
192 ModuleBase_ModelWidget* anActiveWdg = module()->activeWidget();
193 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWdg);
195 aProcessor->mouseMoved(theWnd, theEvent);
202 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
203 QMouseEvent* /* theEvent*/)
205 return isActiveMgr() && myIsInternalEditOperation;
208 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
209 QMouseEvent* theEvent)
211 bool aProcessed = false;
215 if (myIsInternalEditOperation) {
216 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
217 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
219 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
220 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
222 // block of viewer update
223 // we need to block update content of the viewer because of Sketch Point feature
224 // in activate() the value of the point is initialized and it can be displayed
225 // but the default value is [0, 0]. So, we block update viewer contentent until
226 // onMouseRelease happens, which correct the point position
227 ModuleBase_Tools::blockUpdateViewer(true);
229 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
230 (myWorkshop->currentOperation());
231 myPreviousFeature = aFOperation->feature();
233 /// selection should be obtained from workshop before ask if the operation can be started as
234 /// the canStartOperation method performs commit/abort of previous operation.
235 /// Sometimes commit/abort
236 /// may cause selection clear(Sketch operation) as a result
237 /// it will be lost and is not used for preselection.
238 ModuleBase_ISelection* aSelection = myWorkshop->selection();
239 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
240 aSelection->getSelected(ModuleBase_ISelection::AllControls);
242 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
243 module()->sketchMgr()->activeSketch());
244 FeaturePtr anExternalCreatedFeature;
245 if (!aPreSelected.empty()) {
246 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
247 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
249 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
252 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
253 ObjectPtr anExternalObject =
254 aPointWidget->getExternalObjectMgr()->getExternalObjectValidated();
255 // if external object is during reentrant operation and is used as a parameter of feature
256 // it should be removed after the operation is restarted. (Circle feature, Projection)
257 if (anExternalObject.get())
258 anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject);
263 // remove created external feature
264 if (anExternalCreatedFeature.get()) {
265 QObjectPtrList anObjects;
266 anObjects.append(anExternalCreatedFeature);
267 workshop()->deleteFeatures(anObjects);
270 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
271 mySelectedObject = ObjectPtr();
272 mySelectedAttribute = AttributePtr();
274 myPreviousFeature = FeaturePtr();
277 // fill the first widget by the mouse event point
278 // if the active widget is not the first, it means that the restarted operation is filled by
279 // the current preselection.
280 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
281 module()->activeWidget());
282 //PartSet_WidgetPoint2D* aPoint2DWdg =
283 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
284 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
285 aPanel->findFirstAcceptingValueWidget());
286 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
287 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
288 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
289 if (!aPreSelected.empty())
290 aSelectedPrs = aPreSelected.front();
291 if (aSelectedPrs.get() && aSelectedPrs->object().get()
292 && !aSelectedPrs->object()->data()->isValid()) {
293 // the selected object was removed diring restart, e.g. presentable macro feature
294 // there are created objects to replace the object depending on created feature kind
295 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
297 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
298 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
299 //if (!aPreSelected.empty())
300 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
302 // unblock viewer update
303 ModuleBase_Tools::blockUpdateViewer(false);
309 //******************************************************
310 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
311 const std::shared_ptr<Events_Message>& theMessage)
313 ReentrantMessagePtr aReentrantMessage =
314 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
315 if (!aReentrantMessage.get())
318 // if feature has already filled the selected object, we should not overwrite it
319 if (!aReentrantMessage->selectedObject().get())
320 aReentrantMessage->setSelectedObject(mySelectedObject);
322 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
323 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
326 //void PartSet_SketcherReentrantMgr::onWidgetActivated()
328 // if (!isActiveMgr())
330 // if (!myIsInternalEditOperation)
333 // PartSet_Module* aModule = module();
334 // ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
335 // ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
336 // if (aFirstWidget != aPanel->activeWidget()) {
337 // ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
340 // myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
345 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
348 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
354 // we should avoid processing of the signal about no more widgets attributes and
355 // do this after the restart operaion is finished if it was called
356 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
357 // if it should be called after restart
358 if (myIsFlagsBlocked) {
359 myNoMoreWidgetsAttribute = thePreviousAttributeID;
363 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
364 (myWorkshop->currentOperation());
365 if (module()->sketchMgr()->isDragModeCreation()) {
366 if (aFOperation && myIsAutoConstraints)
367 addConstraints(aFOperation->feature());
370 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
373 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
374 if (aFOperation->isNeedToBeAborted()) {
375 aFOperation->abort();
378 bool isStarted = false;
379 if (!module()->sketchMgr()->sketchSolverError()) {
380 if (myRestartingMode != RM_Forbided) {
381 myRestartingMode = RM_LastFeatureUsed;
382 isStarted = startInternalEdit(thePreviousAttributeID);
386 if (myIsAutoConstraints)
387 addConstraints(aFOperation->feature());
388 aFOperation->commit();
394 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
401 // empty previous attribute means that the Apply/Ok button has focus and the enter
402 // should not lead to start edition mode of the previous operation
403 if (thePreviousAttributeID.empty())
406 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
407 (myWorkshop->currentOperation());
408 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
411 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
413 if (!isSketchSolverError) {
414 myRestartingMode = RM_EmptyFeatureUsed;
415 // It seems that the call is obsolete for Enter key processing
416 // It prevent finalysing of the current operation by Enter key
417 //isDone = startInternalEdit(thePreviousAttributeID);
423 void PartSet_SketcherReentrantMgr::onVertexSelected()
428 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
429 std::string anOperationId = anOperation->id().toStdString();
430 if (anOperationId == SketchPlugin_Line::ID() ||
431 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
432 /// If last line finished on vertex the lines creation sequence has to be break
433 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
434 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
435 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
436 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
437 bool aFoundWidget = false;
438 bool aFoundObligatory = false;
439 for (; anIt != aLast && !aFoundObligatory; anIt++) {
441 aFoundWidget = *anIt == anActiveWidget;
443 aFoundObligatory = (*anIt)->isObligatory();
445 if (!aFoundObligatory)
446 myRestartingMode = RM_Forbided;
450 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
452 if (isInternalEditActive()) {
453 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
454 if (!aWidget->isModifiedInEdit().empty())
459 void PartSet_SketcherReentrantMgr::onBeforeStopped()
461 if (!isActiveMgr() || !myIsInternalEditOperation)
464 beforeStopInternalEdit();
467 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
469 return !isActiveMgr() || myRestartingMode == RM_None;
472 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
474 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
476 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
478 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
479 if (anActive) { // the manager is not active when the current operation is a usual Edit
480 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
481 (myWorkshop->currentOperation());
482 if (aFOperation->isEditOperation())
483 anActive = myIsInternalEditOperation;
489 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
492 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
496 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
497 /// event comes two times, so we should not start another internal edit operation
498 /// the Apply button becomes disabled becase the second additional internal feature is created
499 if (myIsInternalEditOperation)
502 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
503 (myWorkshop->currentOperation());
505 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
506 /// improvement to deselect automatically all eventual selected objects, when
507 // returning to the neutral point of the Sketcher or start internal edit
508 workshop()->selector()->clearSelection();
510 if (myIsAutoConstraints)
511 addConstraints(aFOperation->feature());
513 aFOperation->setEditOperation(true/*, false*/);
514 createInternalFeature();
516 myIsInternalEditOperation = true;
517 updateAcceptAllAction();
520 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
521 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
523 // activate selection filters of the first widget in the viewer
524 //onWidgetActivated();
526 // activate the last active widget in the Property Panel
527 if (!thePreviousAttributeID.empty()) {
528 ModuleBase_Operation* anEditOperation = module()->currentOperation();
529 if (anEditOperation) {
530 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
531 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
532 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
533 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
534 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
535 // workaround for the same attributes used in different stacked widgets(attribute types)
536 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
538 aPreviousAttributeWidget = aWidgets[i];
541 // If the current widget is a selector, do nothing, it processes the mouse press
542 if (aPreviousAttributeWidget) {
543 if (!aPreviousAttributeWidget->isViewerSelector()) {
544 aPreviousAttributeWidget->focusTo();
545 aPreviousAttributeWidget->emitFocusInWidget();
546 aPreviousAttributeWidget->selectContent();
549 // in case of shape multi selector, the widget does not lose focus by filling
550 // like it is in shape selector. So, if enter is pressed, the multi shape selector
551 // control should be deactivated. The focus is moved to Apply button and there
552 // should not be active control visualized in property panel
553 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
554 aPanel->activateWidget(NULL, false);
556 // if there is no the next widget to be automatically activated,
557 // the Ok button in property
558 // panel should accept the focus(example is parallel constraint on sketch lines)
559 QToolButton* anOkBtn =
560 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
562 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
569 module()->sketchMgr()->clearClickedFlags();
574 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
576 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
577 (myWorkshop->currentOperation());
579 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
580 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
583 deleteInternalFeature();
586 void PartSet_SketcherReentrantMgr::restartOperation()
589 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
592 if (myIsInternalEditOperation) {
593 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
594 myWorkshop->currentOperation());
596 ModuleBase_ISelection* aSelection = myWorkshop->selection();
597 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
598 aSelection->getSelected(ModuleBase_ISelection::AllControls);
600 if (myInternalFeature.get())
601 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
602 module()->sketchMgr()->activeSketch());
604 myNoMoreWidgetsAttribute = "";
605 myIsFlagsBlocked = true;
606 /// launch has 'false' parameter to do not start new operation if the previous operation
607 /// is not committed. It is important for Line Sketch feature as it uses the previous
608 /// created feature parameter(to build coincidence), but by abort the previous is removed
609 module()->launchOperation(aFOperation->id(), true);
610 myIsFlagsBlocked = false;
613 // we should avoid processing of the signal about no more widgets attributes and
614 // do this after the restart operaion is finished if it was called
615 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
616 // if it should be called after restart
617 if (!myNoMoreWidgetsAttribute.empty()) {
618 onNoMoreWidgets(myNoMoreWidgetsAttribute);
619 myNoMoreWidgetsAttribute = "";
625 void PartSet_SketcherReentrantMgr::createInternalFeature()
627 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
628 (myWorkshop->currentOperation());
630 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
631 FeaturePtr anOperationFeature = aFOperation->feature();
633 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
634 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
637 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
638 << myInternalFeature->data()->name() << std::endl;
641 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
643 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
644 (aFOperation->propertyPanel());
646 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
647 myInternalWidget->setVisible(false);
649 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
651 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
652 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
654 aFactory.createWidget(anInternalPage);
655 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
657 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
658 bool isStoreValue = !aFOperation->isEditOperation() &&
659 !aWidget->getDefaultValue().empty() &&
660 !aWidget->isComputedDefault();
661 aWidget->setFeature(myInternalFeature, isStoreValue);
662 if (!isStoreValue && isFeatureChanged)
663 aWidget->restoreValue();
666 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
669 setInternalActiveWidget(aFirstWidget);
673 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
676 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
677 << myInternalFeature->data()->name() << std::endl;
679 setInternalActiveWidget(0);
680 delete myInternalWidget;
681 myInternalWidget = 0;
683 QObjectPtrList anObjects;
684 anObjects.append(myInternalFeature);
685 workshop()->deleteFeatures(anObjects);
686 myInternalFeature = FeaturePtr();
689 void PartSet_SketcherReentrantMgr::resetFlags()
691 if (!myIsFlagsBlocked) {
692 myIsInternalEditOperation = false;
693 updateAcceptAllAction();
694 myRestartingMode = RM_None;
695 myReentrantMessage = std::shared_ptr<Events_Message>();
699 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
700 const FeaturePtr& theNewFeature,
701 const CompositeFeaturePtr& theSketch,
702 const bool /*isTemporary*/)
704 bool aChanged = false;
705 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
706 !theSourceFeature->data()->isValid())
710 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
711 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
715 std::string aFeatureKind = theSourceFeature->getKind();
716 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
717 // Initialize new line with first point equal to end of previous
718 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
719 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
720 aSFData->attribute(SketchPlugin_Line::END_ID()));
721 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
722 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
723 aNFData->attribute(SketchPlugin_Line::START_ID()));
724 aNPoint->setValue(aSPoint->x(), aSPoint->y());
725 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
727 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
728 aSFData->attribute(SketchPlugin_Line::END_ID()));
729 aNPoint->setValue(aSPoint->x(), aSPoint->y());
731 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
733 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_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 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
741 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
743 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
744 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
745 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
746 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
747 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
748 //// if the arc is tangent, set coincidence to end point of the previous arc
749 //std::string anArcType = aSourceFeatureTypeAttr->value();
750 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
751 // // get the last point of the previuos arc feature(geom point 2d)
752 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
753 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
754 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
755 // aSData->attribute(SketchPlugin_Arc::END_ID()));
756 // // get point attribute on the current feature
757 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
758 // SketchPlugin_Arc::TANGENT_POINT_ID());
759 // aTangentPointAttr->setAttr(aSPointAttr);
761 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
762 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
763 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
764 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
767 //ModuleBase_Tools::flushUpdated(theNewFeature);
770 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
771 aFeatureKind == SketchPlugin_Split::ID()) {
772 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
773 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
774 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
775 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
776 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
777 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
778 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
779 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
780 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
781 theNewFeature->data()->attribute(aPreviewObjectAttribute));
782 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
783 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
784 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
785 theSourceFeature->data()->attribute(aPreviewPointAttribute));
786 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
787 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
788 theNewFeature->data()->attribute(aPreviewPointAttribute));
789 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
794 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
795 const CompositeFeaturePtr& /*theSketch*/) const
797 bool aTangentArc = false;
798 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
800 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
801 FeaturePtr aFeature = aFOperation->feature();
802 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
803 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
804 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
805 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
811 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
813 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
815 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
818 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
820 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
821 return aConnector->workshop();
824 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
826 return dynamic_cast<PartSet_Module*>(myWorkshop->module());
829 void PartSet_SketcherReentrantMgr::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
831 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
832 (myWorkshop->currentOperation());
835 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
836 (aFOperation->propertyPanel());
838 aPropertyPanel->setInternalActiveWidget(theWidget);
842 void PartSet_SketcherReentrantMgr::onAutoConstraints(bool isOn)
844 myIsAutoConstraints = isOn;
847 void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature)
849 if (theFeature->getKind() != SketchPlugin_Line::ID())
852 static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0));
853 static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1));
855 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
856 std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
857 aData->attribute(SketchPlugin_Line::START_ID()));
858 std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
859 aData->attribute(SketchPlugin_Line::END_ID()));
860 if (aPoint1.get() && aPoint2.get()) {
861 GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPoint1->pnt(), aPoint2->pnt()));
862 GeomDir2dPtr aDir = aLine->direction();
863 double aHorAngle = fabs(myHorDir->angle(aDir));
864 double aVertAngle = fabs(myVertDir->angle(aDir));
865 if (aHorAngle > M_PI/2.)
866 aHorAngle = M_PI - aHorAngle;
867 if (aVertAngle > M_PI/2.)
868 aVertAngle = M_PI - aVertAngle;
870 double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
871 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
873 if (aHorAngle < aTolerance) {
874 // Add horizontal constraint
875 aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
877 else if (aVertAngle < aTolerance) {
878 // Add vertical constraint
879 aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID());
881 if (aFeature.get()) {
882 aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(
883 theFeature->firstResult());
884 myLastAutoConstraint = aFeature.get();
890 bool PartSet_SketcherReentrantMgr::isLastAutoConstraint(const ObjectPtr& theObj) const
892 return theObj.get() == myLastAutoConstraint;