-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#include "PartSet_SketcherReentrantMgr.h"
+#include "PartSet_ExternalObjectsMgr.h"
#include "PartSet_Module.h"
#include "PartSet_SketcherMgr.h"
#include "PartSet_WidgetPoint2d.h"
#include "ModelAPI_Session.h"
#include "ModelAPI_AttributeString.h"
#include "ModelAPI_AttributeRefAttr.h"
+#include "ModelAPI_AttributeReference.h"
#include "ModelAPI_EventReentrantMessage.h"
#include "GeomDataAPI_Point2D.h"
+#include "GeomAPI_Lin2d.h"
+#include "GeomAPI_Dir2d.h"
+
#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ISelectionActivate.h>
#include <ModuleBase_OperationFeature.h>
#include <ModuleBase_ModelWidget.h>
#include <ModuleBase_ViewerPrs.h>
#include <SketchPlugin_MacroCircle.h>
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Trim.h>
+#include <SketchPlugin_Split.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
+#include <SketchPlugin_ConstraintVertical.h>
#include <XGUI_Workshop.h>
#include <XGUI_ModuleConnector.h>
myRestartingMode(RM_None),
myIsFlagsBlocked(false),
myIsInternalEditOperation(false),
- myInternalActiveWidget(0),
- myNoMoreWidgetsAttribute("")
+ myNoMoreWidgetsAttribute(""),
+ myIsAutoConstraints(true),
+ myLastAutoConstraint(0)
{
}
{
}
-ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
-{
- ModuleBase_ModelWidget* aWidget = 0;
- if (!isActiveMgr())
- return aWidget;
-
- ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
- if (anOperation) {
- ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
- if (aPanel) { // check for case when the operation is started but property panel is not filled
- ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
- if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
- aWidget = myInternalActiveWidget;
- }
- }
- return aWidget;
-}
-
bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
{
return myIsInternalEditOperation;
if (!isActiveMgr())
return;
- if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
- ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
- myWorkshop->currentOperation());
- CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
- if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
- copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
- }
+ //if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
+ //ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
+ // myWorkshop->currentOperation());
+ //CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
+ //if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
+ //copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
+ //}
resetFlags();
}
myPreviousFeature = FeaturePtr();
anActiveWidget = module()->activeWidget();
- aCurrentFeature = anActiveWidget->feature();
aProcessed = true;
- if (anActiveWidget->attributeID() == anAttributeOnStart) {
+ if (anActiveWidget && anActiveWidget->attributeID() == anAttributeOnStart) {
// it was not deactivated by preselection processing
aPanel->activateNextWidget(anActiveWidget);
}
} else {
// processing mouse move in active widget of restarted operation
- ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
- PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
+ ModuleBase_ModelWidget* anActiveWdg = module()->activeWidget();
+ PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWdg);
if (aProcessor)
aProcessor->mouseMoved(theWnd, theEvent);
}
myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
module()->sketchMgr()->activeSketch());
- if (!aPreSelected.empty())
- module()->getGeomSelection(aPreSelected.first(), mySelectedObject, mySelectedAttribute);
+ FeaturePtr anExternalCreatedFeature;
+ if (!aPreSelected.empty()) {
+ ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
+ module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
+
+ PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
+ if (aPointWidget) {
+ GeomShapePtr aShape;
+ aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
+ ObjectPtr anExternalObject =
+ aPointWidget->getExternalObjectMgr()->getExternalObjectValidated();
+ // if external object is during reentrant operation and is used as a parameter of feature
+ // it should be removed after the operation is restarted. (Circle feature, Projection)
+ if (anExternalObject.get())
+ anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject);
+ }
+ }
restartOperation();
+ // remove created external feature
+ if (anExternalCreatedFeature.get()) {
+ QObjectPtrList anObjects;
+ anObjects.append(anExternalCreatedFeature);
+ workshop()->deleteFeatures(anObjects);
+ }
+
myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
mySelectedObject = ObjectPtr();
mySelectedAttribute = AttributePtr();
&& !aSelectedPrs->object()->data()->isValid()) {
// the selected object was removed diring restart, e.g. presentable macro feature
// there are created objects to replace the object depending on created feature kind
- aSelectedPrs = generatePreSelection();
+ aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
}
aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
//aPoint2DWdg->mouseReleased(theWindow, theEvent);
aReentrantMessage->setClickedPoint(myClickedSketchPoint);
}
-void PartSet_SketcherReentrantMgr::onWidgetActivated()
-{
- if (!isActiveMgr())
- return;
- if (!myIsInternalEditOperation)
- return;
-
- PartSet_Module* aModule = module();
- ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
- ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
- if (aFirstWidget != aPanel->activeWidget()) {
- ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
- if (aWSelector)
- aWSelector->activateSelectionAndFilters(true);
- }
-}
+//void PartSet_SketcherReentrantMgr::onWidgetActivated()
+//{
+// if (!isActiveMgr())
+// return;
+// if (!myIsInternalEditOperation)
+// return;
+//
+// PartSet_Module* aModule = module();
+// ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
+// ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
+// if (aFirstWidget != aPanel->activeWidget()) {
+// ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
+// (aFirstWidget);
+// if (aWSelector) {
+// myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
+// }
+// }
+//}
void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
{
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(myWorkshop->currentOperation());
+ if (module()->sketchMgr()->isDragModeCreation()) {
+ if (aFOperation && myIsAutoConstraints)
+ addConstraints(aFOperation->feature());
+ return;
+ }
if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
return;
if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
- bool isStarted = false;
- if (!module()->sketchMgr()->sketchSolverError()) {
- if (myRestartingMode != RM_Forbided) {
- myRestartingMode = RM_LastFeatureUsed;
- isStarted = startInternalEdit(thePreviousAttributeID);
+ if (aFOperation->isNeedToBeAborted()) {
+ aFOperation->abort();
+ }
+ else {
+ bool isStarted = false;
+ if (!module()->sketchMgr()->sketchSolverError()) {
+ if (myRestartingMode != RM_Forbided) {
+ myRestartingMode = RM_LastFeatureUsed;
+ isStarted = startInternalEdit(thePreviousAttributeID);
+ }
+ }
+ if (!isStarted) {
+ if (myIsAutoConstraints)
+ addConstraints(aFOperation->feature());
+ aFOperation->commit();
}
}
- if (!isStarted)
- aFOperation->commit();
}
}
if (!isSketchSolverError) {
myRestartingMode = RM_EmptyFeatureUsed;
- isDone = startInternalEdit(thePreviousAttributeID);
+ // It seems that the call is obsolete for Enter key processing
+ // It prevent finalysing of the current operation by Enter key
+ //isDone = startInternalEdit(thePreviousAttributeID);
}
return isDone;
void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
{
-
if (isInternalEditActive()) {
- ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
- (myWorkshop->currentOperation());
ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
if (!aWidget->isModifiedInEdit().empty())
restartOperation();
(myWorkshop->currentOperation());
if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
+ /// improvement to deselect automatically all eventual selected objects, when
+ // returning to the neutral point of the Sketcher or start internal edit
+ workshop()->selector()->clearSelection();
+
+ if (myIsAutoConstraints)
+ addConstraints(aFOperation->feature());
+
aFOperation->setEditOperation(true/*, false*/);
createInternalFeature();
connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
// activate selection filters of the first widget in the viewer
- onWidgetActivated();
+ //onWidgetActivated();
// activate the last active widget in the Property Panel
if (!thePreviousAttributeID.empty()) {
QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
- /// workaround for the same attributes used in different stacked widgets(attribute types)
- if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
- continue;
+ // workaround for the same attributes used in different stacked widgets(attribute types)
+ if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
+ continue;
aPreviousAttributeWidget = aWidgets[i];
}
}
if (aPreviousAttributeWidget) {
if (!aPreviousAttributeWidget->isViewerSelector()) {
aPreviousAttributeWidget->focusTo();
+ aPreviousAttributeWidget->emitFocusInWidget();
aPreviousAttributeWidget->selectContent();
}
else {
QToolButton* anOkBtn =
dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
if (anOkBtn)
- anOkBtn->setFocus(Qt::TabFocusReason);
+ ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
}
}
}
if (myInternalFeature.get())
copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
- module()->sketchMgr()->activeSketch());
+ module()->sketchMgr()->activeSketch());
myNoMoreWidgetsAttribute = "";
myIsFlagsBlocked = true;
ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
(aWidgets);
if (aFirstWidget)
- myInternalActiveWidget = aFirstWidget;
+ setInternalActiveWidget(aFirstWidget);
}
}
std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
<< myInternalFeature->data()->name() << std::endl;
#endif
- if (myInternalActiveWidget) {
- ModuleBase_WidgetSelector* aWSelector =
- dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
- if (aWSelector)
- aWSelector->activateSelectionAndFilters(false);
- myInternalActiveWidget = 0;
- }
+ setInternalActiveWidget(0);
delete myInternalWidget;
myInternalWidget = 0;
//ModuleBase_Tools::flushUpdated(theNewFeature);
//aChanged = true;
}
- else if (aFeatureKind == SketchPlugin_Trim::ID()) {
- /*std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
+ else if (aFeatureKind == SketchPlugin_Trim::ID() ||
+ aFeatureKind == SketchPlugin_Split::ID()) {
+ std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
+ SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
+ std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
+ SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
+ std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- theSourceFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
- std::shared_ptr<ModelAPI_AttributeReference> aNRefSelectedAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
- aNRefSelectedAttr->setValue(aRefSelectedAttr->value());*/
-
- /*std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
+ theSourceFeature->data()->attribute(aPreviewObjectAttribute));
std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
- aNRefPreviewAttr->setValue(aRefPreviewAttr->value());*/
-
- /*std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theSourceFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
- std::shared_ptr<GeomDataAPI_Point2D> aNPointSelectedAttr =
+ theNewFeature->data()->attribute(aPreviewObjectAttribute));
+ aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
+ std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
- aNPointSelectedAttr->setValue(aPointSelectedAttr->x(), aPointSelectedAttr->y());
- */
- /*std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
+ theSourceFeature->data()->attribute(aPreviewPointAttribute));
std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
+ theNewFeature->data()->attribute(aPreviewPointAttribute));
aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
- */
- //aChanged = true;
}
return aChanged;
}
return aTangentArc;
}
-std::shared_ptr<ModuleBase_ViewerPrs> PartSet_SketcherReentrantMgr::generatePreSelection()
-{
- std::shared_ptr<ModuleBase_ViewerPrs> aPrs;
-
- return aPrs;
-}
-
void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
{
CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
{
return dynamic_cast<PartSet_Module*>(myWorkshop->module());
}
+
+void PartSet_SketcherReentrantMgr::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
+{
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (myWorkshop->currentOperation());
+ if (aFOperation)
+ {
+ XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
+ (aFOperation->propertyPanel());
+ if (aPropertyPanel)
+ aPropertyPanel->setInternalActiveWidget(theWidget);
+ }
+}
+
+void PartSet_SketcherReentrantMgr::onAutoConstraints(bool isOn)
+{
+ myIsAutoConstraints = isOn;
+}
+
+void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature)
+{
+ if (theFeature->getKind() != SketchPlugin_Line::ID())
+ return;
+
+ static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0));
+ static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1));
+
+ std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aData->attribute(SketchPlugin_Line::START_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aData->attribute(SketchPlugin_Line::END_ID()));
+ if (aPoint1.get() && aPoint2.get()) {
+ GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPoint1->pnt(), aPoint2->pnt()));
+ GeomDir2dPtr aDir = aLine->direction();
+ double aHorAngle = fabs(myHorDir->angle(aDir));
+ double aVertAngle = fabs(myVertDir->angle(aDir));
+ if (aHorAngle > M_PI/2.)
+ aHorAngle = M_PI - aHorAngle;
+ if (aVertAngle > M_PI/2.)
+ aVertAngle = M_PI - aVertAngle;
+
+ double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
+ CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
+ FeaturePtr aFeature;
+ if (aHorAngle < aTolerance) {
+ // Add horizontal constraint
+ aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
+ }
+ else if (aVertAngle < aTolerance) {
+ // Add vertical constraint
+ aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID());
+ }
+ if (aFeature.get()) {
+ aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(
+ theFeature->firstResult());
+ myLastAutoConstraint = aFeature.get();
+ }
+ }
+}
+
+
+bool PartSet_SketcherReentrantMgr::isLastAutoConstraint(const ObjectPtr& theObj) const
+{
+ return theObj.get() == myLastAutoConstraint;
+}