From: vsv Date: Tue, 31 Jul 2018 14:06:53 +0000 (+0300) Subject: Issue #2504: Dimension presentations were added X-Git-Tag: SHAPER_V9_1_0RC1~73^2~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1ae7f64ebf85563bfabdf6163aa65931fea36a08;p=modules%2Fshaper.git Issue #2504: Dimension presentations were added --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 3159cfe72..9d466ae67 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -133,6 +133,8 @@ INCLUDE_DIRECTORIES( ../GeomAlgoAPI ../GeomValidators ../Events + ../Config + ${CAS_INCLUDE_DIRS} ) SET(PROJECT_LIBRARIES @@ -141,6 +143,9 @@ SET(PROJECT_LIBRARIES GeomAPI GeomAlgoAPI GeomValidators + Config + ${CAS_VIEWER} + ${CAS_SHAPE} ) ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp index f038ecc95..56cc199db 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp @@ -37,10 +37,20 @@ #include +#include + +#include +#include +#include +#include +#include +#include +#include + #include #include -FeaturesPlugin_Measurement::FeaturesPlugin_Measurement() +FeaturesPlugin_Measurement::FeaturesPlugin_Measurement() : mySceenScale(1) { } @@ -305,3 +315,267 @@ void FeaturesPlugin_Measurement::computeAngleByPoints() aValues->setSize(1); aValues->setValue(0, anAngleValue); } + +AISObjectPtr FeaturesPlugin_Measurement::getAISObject(AISObjectPtr thePrevious) +{ + AISObjectPtr anAIS; + std::string aKind = string(MEASURE_KIND())->value(); + if (aKind == MEASURE_LENGTH()) + anAIS = lengthDimension(thePrevious); + else if (aKind == MEASURE_DISTANCE()) + anAIS = distanceDimension(thePrevious); + else if (aKind == MEASURE_RADIUS()) + anAIS = radiusDimension(thePrevious); + else if (aKind == MEASURE_ANGLE()) + anAIS = angleDimension(thePrevious); + else if (aKind == MEASURE_ANGLE_POINTS()) + anAIS = angleByPointsDimension(thePrevious); + setupDimension(anAIS); + return anAIS; +} + +AISObjectPtr FeaturesPlugin_Measurement::lengthDimension(AISObjectPtr thePrevious) +{ + AISObjectPtr aAISObj; + if (!myScreenPlane.get()) + return aAISObj; + + AttributeSelectionPtr aSelectedFeature = selection(EDGE_FOR_LENGTH_ID()); + + GeomShapePtr aShape; + GeomEdgePtr anEdge; + if (aSelectedFeature && aSelectedFeature->isInitialized()) { + aShape = aSelectedFeature->value(); + if (!aShape && aSelectedFeature->context()) + aShape = aSelectedFeature->context()->shape(); + } + if (aShape && aShape->isEdge()) + anEdge = GeomEdgePtr(new GeomAPI_Edge(aShape)); + if (anEdge) { + TopoDS_Edge aTEdge = TopoDS::Edge(anEdge->impl()); + GeomPointPtr aPoint1 = anEdge->firstPoint(); + GeomPointPtr aPoint2 = anEdge->lastPoint(); + + gp_Pnt aPnt1(aPoint1->impl()); + gp_Pnt aPnt2(aPoint2->impl()); + + double aLength = aPnt1.Distance(aPnt2); + gp_Pln aPlane = myScreenPlane->impl(); // gce_MP.Value(); + aPlane.SetLocation(aPnt1); + + Handle(AIS_LengthDimension) aDim; + if (thePrevious.get()) { + aAISObj = thePrevious; + Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); + aDim = Handle(AIS_LengthDimension)::DownCast(aAIS); + if (aDim.IsNull()) { + aDim = new AIS_LengthDimension(aTEdge, aPlane); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } else { + aDim->SetMeasuredGeometry(aTEdge, aPlane); + } + } else { + aDim = new AIS_LengthDimension(aTEdge, aPlane); + aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } + aDim->SetFlyout(aLength / 3.); + } + return aAISObj; +} + +AISObjectPtr FeaturesPlugin_Measurement::distanceDimension(AISObjectPtr thePrevious) +{ + AISObjectPtr aAISObj; + if (!myScreenPlane.get()) + return aAISObj; + + AttributeSelectionPtr aFirstFeature = selection(DISTANCE_FROM_OBJECT_ID()); + AttributeSelectionPtr aSecondFeature = selection(DISTANCE_TO_OBJECT_ID()); + if (aFirstFeature.get() && aSecondFeature.get()) { + GeomShapePtr aShape1; + GeomShapePtr aShape2; + if (aFirstFeature->isInitialized() && aSecondFeature->isInitialized()) { + aShape1 = aFirstFeature->value(); + if (!aShape1 && aFirstFeature->context()) + aShape1 = aFirstFeature->context()->shape(); + aShape2 = aSecondFeature->value(); + if (!aShape2 && aSecondFeature->context()) + aShape2 = aSecondFeature->context()->shape(); + } + + if (aShape1 && aShape2) { + const TopoDS_Shape& aShp1 = aShape1->impl(); + const TopoDS_Shape& aShp2 = aShape2->impl(); + BRepExtrema_DistShapeShape aDist(aShp1, aShp2); + aDist.Perform(); + if (aDist.IsDone()) { + gp_Pnt aPnt1 = aDist.PointOnShape1(1); + gp_Pnt aPnt2 = aDist.PointOnShape2(1); + double aDistance = aDist.Value(); + gp_Pln aPlane = myScreenPlane->impl(); + aPlane.SetLocation(aPnt1); + + Handle(AIS_LengthDimension) aDim; + if (thePrevious.get()) { + aAISObj = thePrevious; + Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); + aDim = Handle(AIS_LengthDimension)::DownCast(aAIS); + if (aDim.IsNull()) { + aDim = new AIS_LengthDimension(aPnt1, aPnt2, aPlane); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } else { + aDim->SetMeasuredGeometry(aPnt1, aPnt2, aPlane); + aDim->SetFlyout(aDistance / 3.); + } + } else { + aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + aDim = new AIS_LengthDimension(aPnt1, aPnt2, aPlane); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } + aDim->SetFlyout(aDistance / 3.); + } + } + } + return aAISObj; +} + +AISObjectPtr FeaturesPlugin_Measurement::radiusDimension(AISObjectPtr thePrevious) +{ + AISObjectPtr aAISObj; + AttributeSelectionPtr aSelectedFeature = selection(CIRCULAR_OBJECT_ID()); + + GeomShapePtr aShape; + if (aSelectedFeature && aSelectedFeature->isInitialized()) { + aShape = aSelectedFeature->value(); + if (!aShape && aSelectedFeature->context()) + aShape = aSelectedFeature->context()->shape(); + } + if (aShape.get()) { + TopoDS_Shape aShp = aShape->impl(); + Handle(AIS_RadiusDimension) aDim; + if (thePrevious.get()) { + aAISObj = thePrevious; + Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); + Handle(AIS_RadiusDimension) aDim = Handle(AIS_RadiusDimension)::DownCast(aAIS); + if (aDim.IsNull()) { + aDim = new AIS_RadiusDimension(aShp); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } else + aDim->SetMeasuredGeometry(aShp); + } else { + aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + Handle(AIS_RadiusDimension) aDim = new AIS_RadiusDimension(aShp); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } + } + return aAISObj; +} + +AISObjectPtr FeaturesPlugin_Measurement::angleDimension(AISObjectPtr thePrevious) +{ + AISObjectPtr aAISObj; + AttributeSelectionPtr aFirstFeature = selection(ANGLE_FROM_EDGE_ID()); + GeomShapePtr aShape1; + GeomEdgePtr anEdge1; + if (aFirstFeature && aFirstFeature->isInitialized()) { + aShape1 = aFirstFeature->value(); + if (!aShape1 && aFirstFeature->context()) + aShape1 = aFirstFeature->context()->shape(); + } + if (aShape1 && aShape1->isEdge()) + anEdge1 = GeomEdgePtr(new GeomAPI_Edge(aShape1)); + + AttributeSelectionPtr aSecondFeature = selection(ANGLE_TO_EDGE_ID()); + GeomShapePtr aShape2; + GeomEdgePtr anEdge2; + if (aSecondFeature && aSecondFeature->isInitialized()) { + aShape2 = aSecondFeature->value(); + if (!aShape2 && aSecondFeature->context()) + aShape2 = aSecondFeature->context()->shape(); + } + if (aShape2 && aShape2->isEdge()) + anEdge2 = GeomEdgePtr(new GeomAPI_Edge(aShape2)); + + if (anEdge1.get() && anEdge2.get()) { + TopoDS_Edge aTEdge1 = TopoDS::Edge(anEdge1->impl()); + TopoDS_Edge aTEdge2 = TopoDS::Edge(anEdge2->impl()); + Handle(AIS_AngleDimension) aDim; + if (thePrevious.get()) { + aAISObj = thePrevious; + Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); + aDim = Handle(AIS_AngleDimension)::DownCast(aAIS); + if (aDim.IsNull()) { + aDim = new AIS_AngleDimension(aTEdge1, aTEdge2); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } else + aDim->SetMeasuredGeometry(aTEdge1, aTEdge2); + } else { + aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + aDim = new AIS_AngleDimension(aTEdge1, aTEdge2); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } + } + return aAISObj; +} + +AISObjectPtr FeaturesPlugin_Measurement::angleByPointsDimension(AISObjectPtr thePrevious) +{ + AISObjectPtr aAISObj; + GeomVertexPtr aVertex1 = selectionToVertex(selection(ANGLE_POINT1_ID())); + GeomVertexPtr aVertex2 = selectionToVertex(selection(ANGLE_POINT2_ID())); + GeomVertexPtr aVertex3 = selectionToVertex(selection(ANGLE_POINT3_ID())); + + if (aVertex1.get() && aVertex2.get() && aVertex3.get()) { + GeomPointPtr aPoint1 = aVertex1->point(); + GeomPointPtr aPoint2 = aVertex2->point(); + GeomPointPtr aPoint3 = aVertex3->point(); + gp_Pnt aPnt1(aPoint1->impl()); + gp_Pnt aPnt2(aPoint2->impl()); + gp_Pnt aPnt3(aPoint3->impl()); + + if (thePrevious.get()) { + aAISObj = thePrevious; + Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); + Handle(AIS_AngleDimension) aDim = Handle(AIS_AngleDimension)::DownCast(aAIS); + if (aDim.IsNull()) { + aDim = new AIS_AngleDimension(aPnt1, aPnt2, aPnt3); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } else + aDim->SetMeasuredGeometry(aPnt1, aPnt2, aPnt3); + } else { + Handle(AIS_AngleDimension) aDim = new AIS_AngleDimension(aPnt1, aPnt2, aPnt3); + aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } + } + return aAISObj; +} + + +void FeaturesPlugin_Measurement::setupDimension(AISObjectPtr theDim) +{ + if (theDim.get()) { + Handle(AIS_InteractiveObject) aAIS = theDim->impl(); + Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAIS); + int aSize = Config_PropManager::integer("Visualization", "dimension_arrow_size"); + int aTextSize = Config_PropManager::integer("Visualization", "dimension_value_size"); + + Handle(Prs3d_DimensionAspect) anAspect = aDim->DimensionAspect(); + anAspect->MakeArrows3d(false); + anAspect->MakeText3d(false); + anAspect->MakeTextShaded(false); + anAspect->MakeUnitsDisplayed(false); + anAspect->MakeUnitsDisplayed(false); + anAspect->TextAspect()->SetFont(Config_PropManager::string("Visualization", + "dimension_font").c_str()); + anAspect->TextAspect()->SetHeight(aTextSize / mySceenScale); + anAspect->ArrowAspect()->SetLength(aSize / mySceenScale); + anAspect->SetExtensionSize((aTextSize / mySceenScale + aSize) / 2.0); + aDim->SetDimensionAspect(anAspect); + + aDim->SetZLayer(1); + std::vector aColor = Config_PropManager::color("Visualization", "sketch_dimension_color"); + theDim->setColor(aColor[0], aColor[1], aColor[2]); + } +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Measurement.h b/src/FeaturesPlugin/FeaturesPlugin_Measurement.h index 27eefc4d5..562d998a7 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Measurement.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Measurement.h @@ -24,6 +24,9 @@ #include "FeaturesPlugin.h" #include +#include +#include + /// \class FeaturesPlugin_Measurement /// \ingroup Plugins /// \brief Feature for calculation metrics. @@ -33,7 +36,9 @@ /// * distance between shapes, /// * radius of arc or cylindrical faces, /// * angle between edges. -class FeaturesPlugin_Measurement : public ModelAPI_Feature +class FeaturesPlugin_Measurement : public ModelAPI_Feature, + public GeomAPI_IPresentable, + public GeomAPI_IScreenParams { public: /// Feature kind. @@ -182,6 +187,23 @@ public: /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true. virtual bool isMacro() const { return true; } + /** Returns the AIS preview + * \param thePrevious - defines a presentation if it was created previously + */ + FEATURESPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + + /// Set current screen plane + /// \param theScreenPlane the screen plane + virtual void setScreenPlane(GeomPlanePtr theScreenPlane) { + myScreenPlane = theScreenPlane; + } + + /// Set current view scale + /// \param theScale the view scale + virtual void setViewScale(double theScale) { + mySceenScale = theScale; + } + /// Use plugin manager for features creation FeaturesPlugin_Measurement(); @@ -196,6 +218,32 @@ private: void computeAngle(); /// Compute angle by three points void computeAngleByPoints(); + + /// Create length dimension presentation + /// \param thePrevious previous version of presentation + AISObjectPtr lengthDimension(AISObjectPtr thePrevious); + + /// Create distance dimension presentation + /// \param thePrevious previous version of presentation + AISObjectPtr distanceDimension(AISObjectPtr thePrevious); + + /// Create radius dimension presentation + /// \param thePrevious previous version of presentation + AISObjectPtr radiusDimension(AISObjectPtr thePrevious); + + /// Create angle dimension presentation + /// \param thePrevious previous version of presentation + AISObjectPtr angleDimension(AISObjectPtr thePrevious); + + /// Create angle by points dimension presentation + /// \param thePrevious previous version of presentation + AISObjectPtr angleByPointsDimension(AISObjectPtr thePrevious); + + /// Set dimension presentation parameters + void setupDimension(AISObjectPtr theDim); + + GeomPlanePtr myScreenPlane; //< a plane of current screen + double mySceenScale; //< a scale of current view }; #endif diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 01594414d..d42c54c57 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -60,6 +60,7 @@ SET(PROJECT_HEADERS GeomAPI_Ellipse.h GeomAPI_Ellipse2d.h GeomAPI_Tools.h + GeomAPI_IScreenParams.h ) SET(PROJECT_SOURCES diff --git a/src/GeomAPI/GeomAPI_IScreenParams.h b/src/GeomAPI/GeomAPI_IScreenParams.h new file mode 100644 index 000000000..8a6c09283 --- /dev/null +++ b/src/GeomAPI/GeomAPI_IScreenParams.h @@ -0,0 +1,50 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// 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 +// + +#ifndef GeomAPI_IScreenParams_H_ +#define GeomAPI_IScreenParams_H_ + +#include "GeomAPI_Pln.h" + +/** +* A class which defines an interface of object which has to be provided with +* current screen parameters +*/ +class GeomAPI_IScreenParams +{ +public: + virtual ~GeomAPI_IScreenParams() {} + + /** + * Set plane of active view screen + * \param theScreenPlane - the screen plane + */ + virtual void setScreenPlane(GeomPlanePtr theScreenPlane) = 0; + + /** + * Set a scale of active view + * \param theScale a view scale + */ + virtual void setViewScale(double theScale) = 0; +}; + +typedef std::shared_ptr GeomScreenParamsPtr; + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 2cf51fbe1..99342671c 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -207,6 +207,23 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) "Hidden faces transparency", Config_Prop::DblSpin, "0.8"); + std::ostringstream aStream; + aStream << SketcherPrs_Tools::getDefaultArrowSize(); + Config_PropManager::registerProp("Visualization", "dimension_arrow_size", + "Dimension arrow size", Config_Prop::IntSpin, aStream.str()); + + Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font", + Config_Prop::String, "Times-bold"); + + aStream.str(""); + aStream.clear(); + aStream << SketcherPrs_Tools::getDefaultTextHeight(); + Config_PropManager::registerProp("Visualization", "dimension_value_size", + "Dimension value size", Config_Prop::IntSpin, aStream.str()); + + Config_PropManager::registerProp("Visualization", "sketch_dimension_color", + "Sketch dimension color", + Config_Prop::Color, SKETCH_DIMENSION_COLOR); } //****************************************************** @@ -1120,10 +1137,12 @@ void PartSet_Module::onViewTransformed(int theTrsfType) if (aView.IsNull()) return; + bool isModified = false; ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation(); if (aCurrentOperation && (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) || - sketchMgr()->isNestedSketchOperation(aCurrentOperation))) + sketchMgr()->isNestedSketchOperation(aCurrentOperation) || + (aCurrentOperation->id() == "Measurement"))) { double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize()); @@ -1131,7 +1150,6 @@ void PartSet_Module::onViewTransformed(int theTrsfType) SketcherPrs_Tools::setArrowSize(aLen); const double aCurScale = aViewer->activeView()->Camera()->Scale(); aViewer->SetScale(aViewer->activeView(), aCurScale); - bool isModified = false; QList aPrsList = aDisplayer->displayedPresentations(); foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) { Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj); @@ -1144,6 +1162,7 @@ void PartSet_Module::onViewTransformed(int theTrsfType) if (isModified) aDisplayer->updateViewer(); } + } //****************************************************** diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index a392b6ef7..4d5aa02e1 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -156,10 +156,6 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() "Sketch auxiliary entity color", Config_Prop::Color, SKETCH_AUXILIARY_COLOR); - Config_PropManager::registerProp("Visualization", "sketch_dimension_color", - "Sketch dimension color", - Config_Prop::Color, SKETCH_DIMENSION_COLOR); - Config_PropManager::registerProp("Visualization", "sketch_overconstraint_color", "Sketch overconstraint color", Config_Prop::Color, SKETCH_OVERCONSTRAINT_COLOR); @@ -178,18 +174,6 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() Config_Prop::Color, XY_PLANE_COLOR); #endif - Config_PropManager::registerProp(SKETCH_TAB_NAME, "dimension_font", "Dimension font", - Config_Prop::String, "Times-bold"); - std::ostringstream aStream; - aStream << SketcherPrs_Tools::getDefaultTextHeight(); - - Config_PropManager::registerProp(SKETCH_TAB_NAME, "dimension_value_size", - "Dimension value size", Config_Prop::IntSpin, aStream.str()); - aStream.str(""); - aStream.clear(); - aStream << SketcherPrs_Tools::getDefaultArrowSize(); - Config_PropManager::registerProp(SKETCH_TAB_NAME, "dimension_arrow_size", - "Dimension arrow size", Config_Prop::IntSpin, aStream.str()); } FeaturePtr SketchPlugin_Plugin::createFeature(std::string theFeatureID) diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index 12e9e1270..34c7401d2 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -94,7 +94,7 @@ void updateArrows(Handle(Prs3d_DimensionAspect) theDimAspect, theDimAspect->SetExtensionSize( (theTextSize / aViewerScale + SketcherPrs_Tools::getArrowSize()) / 2.0); } - theDimAspect->TextAspect()->SetFont(Config_PropManager::string(SKETCH_TAB_NAME, + theDimAspect->TextAspect()->SetFont(Config_PropManager::string("Visualization", "dimension_font").c_str()); theDimAspect->SetArrowTailSize(theDimAspect->ArrowAspect()->Length()); diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 97aa2d015..1054f66c7 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -242,7 +242,7 @@ int getDefaultArrowSize() int getConfigArrowSize() { - return Config_PropManager::integer(SKETCH_TAB_NAME, "dimension_arrow_size"); + return Config_PropManager::integer("Visualization", "dimension_arrow_size"); } static double MyTextHeight = 16; @@ -263,7 +263,7 @@ double getDefaultTextHeight() double getConfigTextHeight() { - return Config_PropManager::integer(SKETCH_TAB_NAME, "dimension_value_size"); + return Config_PropManager::integer("Visualization", "dimension_value_size"); } double getFlyoutDistance(const ModelAPI_Feature* theConstraint) diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 5c3654aca..364153dca 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -50,6 +50,8 @@ #include #include #include +#include +#include #include @@ -163,8 +165,13 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); bool isShading = false; if (aPrs.get() != NULL) { + GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast(theObject); + if (aScreen.get()) { + aScreen->setScreenPlane(getScreenPlane()); + aScreen->setViewScale(getViewScale()); + } anAIS = aPrs->getAISObject(anAIS); - if (anAIS.get()) { + //if (anAIS.get()) { // correct deviation coefficient for /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl(); if (!anAISPrs.IsNull()) { @@ -175,7 +182,7 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes()); } }*/ - } + //} } else { ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (aResult.get() != NULL) { @@ -324,6 +331,11 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); if (aPrs) { + GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast(theObject); + if (aScreen.get()) { + aScreen->setScreenPlane(getScreenPlane()); + aScreen->setViewScale(getViewScale()); + } AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj); if (!aAIS_Obj) { aRedisplayed = erase(theObject, theUpdateViewer); @@ -1119,3 +1131,46 @@ XGUI_SelectionActivate* XGUI_Displayer::selectionActivate() const { return myWorkshop->selectionActivate(); } + +//************************************************************** +GeomPlanePtr XGUI_Displayer::getScreenPlane() const +{ + GeomPlanePtr aResult; + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + Handle(V3d_Viewer) aViewer = aContext->CurrentViewer(); + Handle(V3d_View) aView; + for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) { + aView = aViewer->ActiveView(); + break; + } + if (!aView.IsNull()) { + double aEyeX, aEyeY, aEyeZ; + aView->Eye(aEyeX, aEyeY, aEyeZ); + + double aProjX, aProjY, aProjZ; + aView->Proj(aProjX, aProjY, aProjZ); + + GeomPointPtr aPnt = GeomPointPtr(new GeomAPI_Pnt(aEyeX, aEyeY, aEyeZ)); + GeomDirPtr aDir = GeomDirPtr(new GeomAPI_Dir(aProjX, aProjY, aProjZ)); + + aResult = GeomPlanePtr(new GeomAPI_Pln(aPnt, aDir)); + } + } + return aResult; +} + +double XGUI_Displayer::getViewScale() const +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + Handle(V3d_Viewer) aViewer = aContext->CurrentViewer(); + Handle(V3d_View) aView; + for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) { + aView = aViewer->ActiveView(); + break; + } + return aView->Camera()->Scale(); + } + return 1; +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 870c06af7..5da345d70 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -25,6 +25,7 @@ #include #include +#include #include @@ -351,6 +352,13 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// \return a boolean value static bool isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject); + + /// Returns screen plane of active view + GeomPlanePtr getScreenPlane() const; + + /// Returns scale of active view + double getViewScale() const; + signals: /// Signal on object display /// \param theObject a data object