From 1d23063e3fd8241ef440f0de41d12a03c669aff7 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 12 Feb 2016 21:27:43 +0300 Subject: [PATCH] using the previous type of Circle/Arc during reentrant operation. First correction for tangent arc reentrance from the last point like for the contour line. --- src/ModuleBase/ModuleBase_IPropertyPanel.cpp | 20 +++++- src/ModuleBase/ModuleBase_ToolBox.cpp | 25 +++++++ src/ModuleBase/ModuleBase_ToolBox.h | 7 ++ src/PartSet/PartSet_OperationPrs.cpp | 2 +- src/PartSet/PartSet_SketcherReetntrantMgr.cpp | 65 +++++++++++++++++-- src/PartSet/PartSet_SketcherReetntrantMgr.h | 8 +++ src/SketchPlugin/SketchPlugin_Arc.cpp | 11 ++-- src/SketchPlugin/SketchPlugin_Arc.h | 12 ++++ src/SketchPlugin/SketchPlugin_Circle.h | 6 ++ src/SketchPlugin/plugin-Sketch.xml | 15 ++--- 10 files changed, 149 insertions(+), 22 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.cpp b/src/ModuleBase/ModuleBase_IPropertyPanel.cpp index 0a87a74c8..c37673303 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.cpp +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.cpp @@ -9,6 +9,10 @@ #include "ModuleBase_IPropertyPanel.h" #include "ModuleBase_ModelWidget.h" +#include "ModuleBase_ToolBox.h" + +#include +#include ModuleBase_IPropertyPanel::ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent), myIsEditing(false) { @@ -25,12 +29,24 @@ ModuleBase_ModelWidget* ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget { ModuleBase_ModelWidget* aFirstWidget = 0; + ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); + ModuleBase_ModelWidget* aWgt; QList::const_iterator aWIt; + bool isOffToolBox = false; for (aWIt = theWidgets.begin(); aWIt != theWidgets.end() && !aFirstWidget; ++aWIt) { aWgt = (*aWIt); - if (aWgt->canSetValue()) - aFirstWidget = aWgt; + if (!aValidators->isCase(aWgt->feature(), aWgt->attributeID())) + continue; // this attribute is not participated in the current case + + if (!aWgt->canSetValue()) + continue; + + /// workaround for the same attributes used in different stacked widgets(attribute types) + if (ModuleBase_ToolBox::isOffToolBoxParent(aWgt)) + continue; + + aFirstWidget = aWgt; } return aFirstWidget; } diff --git a/src/ModuleBase/ModuleBase_ToolBox.cpp b/src/ModuleBase/ModuleBase_ToolBox.cpp index 57c7332c6..1ab883c86 100644 --- a/src/ModuleBase/ModuleBase_ToolBox.cpp +++ b/src/ModuleBase/ModuleBase_ToolBox.cpp @@ -5,6 +5,8 @@ // Author: Alexandre SOLOVYOV #include +#include + #include #include #include @@ -76,3 +78,26 @@ void ModuleBase_ToolBox::onButton( int theIndex ) myStack->setCurrentIndex( theIndex ); } +bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget) +{ + bool isOffToolBox = false; + + QList aControls = theWidget->getControls(); + if (aControls.size() > 0) { + QWidget* aFirstControl = aControls.first(); + + QWidget* aWidget = aFirstControl; + QWidget* aParent = (QWidget*)aFirstControl->parent(); + while (aParent) { + QStackedWidget* aStackedWidget = dynamic_cast(aParent); + if (aStackedWidget) { + int anIndex = aStackedWidget->currentIndex(); + isOffToolBox = aStackedWidget->currentWidget() != aWidget; + break; + } + aWidget = aParent; + aParent = (QWidget*)aWidget->parent(); + } + } + return isOffToolBox; +} diff --git a/src/ModuleBase/ModuleBase_ToolBox.h b/src/ModuleBase/ModuleBase_ToolBox.h index 1c2c1ef7d..cab3a788d 100644 --- a/src/ModuleBase/ModuleBase_ToolBox.h +++ b/src/ModuleBase/ModuleBase_ToolBox.h @@ -14,6 +14,7 @@ class QButtonGroup; class QFrame; class QHBoxLayout; class QStackedWidget; +class ModuleBase_ModelWidget; /** * \class ModuleBase_ToolBox @@ -46,6 +47,12 @@ public: /// \param theIdx an index void setCurrentIndex( const int theIdx); + /// Found in the controls of the model widget parent in Stacked Widget + /// returns whether this controls are in the current widget of the stacked widgets + /// \param theWidget a model widget + /// \return boolean result + static bool isOffToolBoxParent(ModuleBase_ModelWidget* theWidget); + signals: /// A signal which is emited on current item changed void currentChanged( int ); diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index aa12287af..fc67747b9 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -121,7 +121,7 @@ bool PartSet_OperationPrs::isVisible(XGUI_Displayer* theDisplayer, const ObjectP aVisible = theDisplayer->isVisible(theObject); // compsolid is not visualized in the viewer, but should have presentation when all sub solids are // visible. It is useful for highlight presentation where compsolid shape is selectable - if (!aVisible && aResult->groupName() == ModelAPI_ResultCompSolid::group()) { + if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) { ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast(aResult); if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0; diff --git a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp index 15cf843d3..93f706d46 100755 --- a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp @@ -6,6 +6,7 @@ #include "PartSet_WidgetPoint2d.h" #include "ModelAPI_Session.h" +#include "ModelAPI_AttributeString.h" #include #include @@ -19,6 +20,8 @@ #include #include +#include +#include #include #include @@ -47,9 +50,9 @@ ModuleBase_ModelWidget* PartSet_SketcherReetntrantMgr::internalActiveWidget() co if (!isActiveMgr()) return aWidget; - ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); - if (aOperation) { - ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); + if (anOperation) { + ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel(); ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector())) aWidget = myInternalActiveWidget; @@ -233,15 +236,33 @@ bool PartSet_SketcherReetntrantMgr::processEnter(const std::string& thePreviousA return isDone; } +/*bool isTangentArc(ModuleBase_Operation* theOperation) +{ + bool aTangentArc = false; + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (theOperation); + if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) { + FeaturePtr aFeature = aFOperation->feature(); + if (aFeature.get() && aFeature->getKind() == SketchPlugin_Arc::ID()) { + AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_Arc::ARC_TYPE()); + std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : ""; + aTangentArc = anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT(); + } + } + + return aTangentArc; +}*/ + void PartSet_SketcherReetntrantMgr::onVertexSelected() { if (!isActiveMgr()) return; - ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); - if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) { + ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); + std::string anOperationId = anOperation->id().toStdString(); + if (anOperationId == SketchPlugin_Line::ID()/* || isTangentArc(anOperation)*/) { /// If last line finished on vertex the lines creation sequence has to be break - ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel(); ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); const QList& aWidgets = aPanel->modelWidgets(); QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end(); @@ -375,8 +396,14 @@ void PartSet_SketcherReetntrantMgr::restartOperation() if (aFOperation) { myNoMoreWidgetsAttribute = ""; myIsFlagsBlocked = true; + FeaturePtr aPrevFeature = aFOperation->feature(); aFOperation->commit(); module()->launchOperation(aFOperation->id()); + // allow the same attribute values in restarted operation + ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast( + myWorkshop->currentOperation()); + copyReetntrantAttributes(aPrevFeature, aCurrentOperation->feature()); + myIsFlagsBlocked = false; resetFlags(); // we should avoid processing of the signal about no more widgets attributes and @@ -391,6 +418,27 @@ void PartSet_SketcherReetntrantMgr::restartOperation() } } +bool PartSet_SketcherReetntrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature, + const FeaturePtr& theNewFeature) +{ + bool aChanged; + std::string aTypeAttributeId; + if (theSourceFeature->getKind() == SketchPlugin_Circle::ID()) { + aTypeAttributeId = SketchPlugin_Circle::CIRCLE_TYPE(); + } + if (theSourceFeature->getKind() == SketchPlugin_Arc::ID()) { + aTypeAttributeId = SketchPlugin_Arc::ARC_TYPE(); + } + if (!aTypeAttributeId.empty()) { + AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId); + AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId); + aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value()); + ModuleBase_ModelWidget::updateObject(theNewFeature); + aChanged = true; + } + return aChanged; +} + void PartSet_SketcherReetntrantMgr::createInternalFeature() { ModuleBase_OperationFeature* aFOperation = dynamic_cast @@ -401,6 +449,8 @@ void PartSet_SketcherReetntrantMgr::createInternalFeature() CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch(); myInternalFeature = aSketch->addFeature(anOperationFeature->getKind()); + + bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature); XGUI_PropertyPanel* aPropertyPanel = dynamic_cast (aFOperation->propertyPanel()); @@ -420,7 +470,10 @@ void PartSet_SketcherReetntrantMgr::createInternalFeature() !aWidget->getDefaultValue().empty() && !aWidget->isComputedDefault(); aWidget->setFeature(myInternalFeature, isStoreValue); + if (!isStoreValue && isFeatureChanged) + aWidget->restoreValue(); } + ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget (aWidgets); if (aFirstWidget) diff --git a/src/PartSet/PartSet_SketcherReetntrantMgr.h b/src/PartSet/PartSet_SketcherReetntrantMgr.h index ebdb0eb16..8f16bce6d 100755 --- a/src/PartSet/PartSet_SketcherReetntrantMgr.h +++ b/src/PartSet/PartSet_SketcherReetntrantMgr.h @@ -139,6 +139,14 @@ private: /// Breaks sequense of automatically resterted operations void resetFlags(); + /// Copy some feature specific attributes from the source to a new feature + /// This is type for Circle and Arc features + /// \param theSourceFeature a source feature + /// \param theNewFeature a new feature + /// \return true is something is copied + static bool copyReetntrantAttributes(const FeaturePtr& theSourceFeature, + const FeaturePtr& theNewFeature); + /// Returns the workshop XGUI_Workshop* workshop() const; diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 2725d8790..ac9981b00 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -42,11 +42,11 @@ const double paramTolerance = 1.e-4; const double PI =3.141592653589793238463; namespace { - static const std::string& ARC_TYPE() + /*static const std::string& ARC_TYPE() { static const std::string TYPE("ArcType"); return TYPE; - } + }*/ static const std::string& ARC_TYPE_CENTER_START_END() { static const std::string TYPE("CenterStartEnd"); @@ -57,11 +57,11 @@ namespace { static const std::string TYPE("ThreePoints"); return TYPE; } - static const std::string& ARC_TYPE_TANGENT() + /*static const std::string& ARC_TYPE_TANGENT() { static const std::string TYPE("Tangent"); return TYPE; - } + }*/ static const std::string& PASSED_POINT_ID() { @@ -140,6 +140,9 @@ void SketchPlugin_Arc::initDerivedClassAttributes() data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RADIUS_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ANGLE_ID()); } void SketchPlugin_Arc::execute() diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index 2bd7c0c44..b3cfa3a2d 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -38,6 +38,18 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese return MY_SKETCH_ARC_ID; } + inline static const std::string& ARC_TYPE() + { + static const std::string TYPE("ArcType"); + return TYPE; + } + + inline static const std::string& ARC_TYPE_TANGENT() + { + static const std::string TYPE("Tangent"); + return TYPE; + } + /// Central 2D point of the circle which contains the arc inline static const std::string& CENTER_ID() { diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index daf4d2651..b6d01897e 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -26,6 +26,12 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPr return MY_CIRCLE_ID; } + inline static const std::string& CIRCLE_TYPE() + { + static const std::string TYPE("CircleType"); + return TYPE; + } + /// 2D point - center of the circle inline static const std::string& CENTER_ID() { diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index c654a5535..24d946c1f 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -62,15 +62,14 @@ - - + @@ -84,18 +83,16 @@ - - + - - + @@ -103,13 +100,13 @@ - + - - + + -- 2.39.2