From: nds Date: Sat, 20 Feb 2016 09:21:00 +0000 (+0300) Subject: #1277 SKETCH : Bad restitution coordinates in the point creation panel X-Git-Tag: V_2.2.0~80 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8abdbb054d2e130d01aaf11ee6d5b984ce1e0b71;p=modules%2Fshaper.git #1277 SKETCH : Bad restitution coordinates in the point creation panel --- diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index 90d41cdff..1640f4137 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -129,39 +129,6 @@ void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a // the presentation is not used in the selection } -bool PartSet_OperationPrs::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject) -{ - bool aVisible = false; - GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aPrs.get() || aResult.get()) { - 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.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; - for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) { - anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i)); - } - aVisible = anAllSubsVisible; - } - } - } - else { - // check if all results of the feature are visible - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - std::list aResults = aFeature->results(); - std::list::const_iterator aIt; - aVisible = !aResults.empty(); - for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - aVisible = aVisible && theDisplayer->isVisible(*aIt); - } - } - return aVisible; -} - bool isSubObject(const ObjectPtr& theObject, const FeaturePtr& theFeature) { bool isSub = false; @@ -224,7 +191,7 @@ void PartSet_OperationPrs::appendShapeIfVisible(ModuleBase_IWorkshop* theWorksho QMap >& theObjectShapes) { XGUI_Displayer* aDisplayer = XGUI_Tools::workshop(theWorkshop)->displayer(); - if (isVisible(aDisplayer, theObject)) { + if (XGUI_Displayer::isVisible(aDisplayer, theObject)) { if (theGeomShape.get()) { if (theObjectShapes.contains(theObject)) theObjectShapes[theObject].append(theGeomShape); diff --git a/src/PartSet/PartSet_OperationPrs.h b/src/PartSet/PartSet_OperationPrs.h index adafbdfb8..6ea0ac622 100755 --- a/src/PartSet/PartSet_OperationPrs.h +++ b/src/PartSet/PartSet_OperationPrs.h @@ -74,13 +74,6 @@ protected: QMap >& featureShapes() { return myFeatureShapes; } private: - /// Return true if the object is visible. If the object is feature, it returns true - /// if all results of the feature are shown - /// \param theDisplayer a displayer - /// \param theObject an object - /// \return a boolean value - static bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject); - /// Fills the map by the feature object and shapes, which should be visuaziled /// Gets feature attributes, collect objects to whom the attributes refer /// \param theFeature a current feature diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index eaa3ec7d1..072143b24 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -8,6 +8,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -57,7 +61,8 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) : ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop), - myValueIsCashed(false), myXValueInCash(0), myYValueInCash(0) + myValueIsCashed(false), myIsFeatureVisibleInCash(true), + myXValueInCash(0), myYValueInCash(0) { if (MyFeaturesForCoincedence.isEmpty()) { MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str() @@ -121,12 +126,9 @@ bool PartSet_WidgetPoint2D::resetCustom() } else { if (myValueIsCashed) { - // fill the control widgets by the cashed value - restoreCurentValue(); - // store value to the model - storeValueCustom(); - setValueState(Stored); - aDone = false; + // if the restored value should be hidden, aDone = true to set + // reset state for the widget in the parent + aDone = restoreCurentValue(); } else { bool isOk; @@ -275,15 +277,34 @@ void PartSet_WidgetPoint2D::storeCurentValue() return; myValueIsCashed = true; + myIsFeatureVisibleInCash = XGUI_Displayer::isVisible( + XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature); myXValueInCash = myXSpin->value(); myYValueInCash = myYSpin->value(); } -void PartSet_WidgetPoint2D::restoreCurentValue() +bool PartSet_WidgetPoint2D::restoreCurentValue() { + bool aRestoredAndHidden = true; + + bool isVisible = myIsFeatureVisibleInCash; + // fill the control widgets by the cashed value + myValueIsCashed = false; + myIsFeatureVisibleInCash = true; ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash); ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash); + + // store value to the model + storeValueCustom(); + if (isVisible) { + setValueState(Stored); + aRestoredAndHidden = false; + } + else + aRestoredAndHidden = true; + + return aRestoredAndHidden; } QList PartSet_WidgetPoint2D::getControls() const diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index a66e11a92..d4271e558 100755 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -124,7 +124,8 @@ protected: void storeCurentValue(); /// Restore cashed value in the model attribute - void restoreCurentValue(); + /// \return boolean state if the restored feature shoud be hidden + bool restoreCurentValue(); /// Fills the widget with default values /// \return true if the widget current value is reset @@ -191,6 +192,7 @@ private: CompositeFeaturePtr mySketch; bool myValueIsCashed; /// boolean state if the value is cashed during value state change + bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled double myXValueInCash; /// the cashed X value during value state change double myYValueInCash; /// the cashed Y value during value state change }; diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 562604dc0..9e92051b7 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -7,6 +7,10 @@ #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" +#include +#include +#include + #include #include #include @@ -26,7 +30,8 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop) +: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop), + myValueIsCashed(false), myIsFeatureVisibleInCash(true), myValueInCash(0) { myFirstPntName = theData->getProperty("first_point"); } @@ -35,6 +40,24 @@ PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance() { } +bool PartSet_WidgetPoint2dDistance::resetCustom() +{ + bool aDone = false; + if (!isUseReset() || isComputedDefault() || mySpinBox->hasVariable()) { + aDone = false; + } + else { + if (myValueIsCashed) { + // if the restored value should be hidden, aDone = true to set + // reset state for the widget in the parent + aDone = restoreCurentValue(); + } + else + aDone = ModuleBase_WidgetDoubleValue::resetCustom(); + } + return aDone; +} + void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt) { @@ -115,12 +138,50 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); std::shared_ptr aPnt = std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); + if (myState != ModifiedInViewer) + storeCurentValue(); + bool isBlocked = blockValueState(true); setPoint(feature(), aPnt); blockValueState(isBlocked); setValueState(ModifiedInViewer); } +void PartSet_WidgetPoint2dDistance::storeCurentValue() +{ + // do not use cash if a variable is used + if (mySpinBox->hasVariable()) + return; + + myValueIsCashed = true; + myIsFeatureVisibleInCash = XGUI_Displayer::isVisible( + XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature); + myValueInCash = mySpinBox->value(); +} + +bool PartSet_WidgetPoint2dDistance::restoreCurentValue() +{ + bool aRestoredAndHidden = true; + + bool isVisible = myIsFeatureVisibleInCash; + // fill the control widgets by the cashed value + + myValueIsCashed = false; + myIsFeatureVisibleInCash = true; + ModuleBase_Tools::setSpinValue(mySpinBox, myValueInCash); + + // store value to the model + storeValueCustom(); + if (isVisible) { + setValueState(Stored); + aRestoredAndHidden = false; + } + else + aRestoredAndHidden = true; + + return aRestoredAndHidden; +} + bool PartSet_WidgetPoint2dDistance::processEnter() { bool isModified = getValueState() == ModifiedInPP; diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index 7b350d33e..1cac83c89 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -74,6 +74,17 @@ public slots: void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); protected: + /// Store current value in cashed value + void storeCurentValue(); + + /// Restore cashed value in the model attribute + /// \return boolean state if the restored feature shoud be hidden + bool restoreCurentValue(); + + /// Fills the widget with default values + /// \return true if the widget current value is reset + virtual bool resetCustom(); + /// The methiod called when widget is activated virtual void activateCustom(); @@ -96,6 +107,10 @@ protected: /// Reference to sketch CompositeFeaturePtr mySketch; + + bool myValueIsCashed; /// boolean state if the value is cashed during value state change + bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled + double myValueInCash; /// the cashed X value during value state change }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index dd84ebdb7..768c0d419 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -410,6 +410,40 @@ int XGUI_Displayer::getSelectionMode(int theShapeType) AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType); } +bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject) +{ + bool aVisible = false; + GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aPrs.get() || aResult.get()) { + 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.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; + for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) { + anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i)); + } + aVisible = anAllSubsVisible; + } + } + } + else { + // check if all results of the feature are visible + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + aVisible = !aResults.empty(); + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + aVisible = aVisible && theDisplayer->isVisible(*aIt); + } + } + return aVisible; +} + + void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList, const bool theUpdateViewer) { diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 5a325fc8c..dd221d7bf 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -247,6 +247,13 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// \param theShapeType a shape type from TopAbs_ShapeEnum static int getSelectionMode(int theShapeType); + /// Return true if the object is visible. If the object is feature, it returns true + /// if all results of the feature are shown + /// \param theDisplayer a displayer + /// \param theObject an object + /// \return a boolean value + static bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject); + signals: /// Signal on object display /// \param theObject a data object