X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_Tools.cpp;h=4e9522fd1f94caec8056f5c4faf59cbd7d613d58;hb=c6745a6b1ad00c0285fab5aeac2cb0d57afef5cc;hp=84d0878f66df2d68817c3f3f12620e322a5bd50b;hpb=ded1e8998ec9d6d57f5a5a122c4abced86874273;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 84d0878f6..4e9522fd1 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: SketcherPrs_Tools.cpp -// Created: 10 March 2015 -// Author: Vitaly SMETANNIKOV +// Copyright (C) 2014-2019 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 +// #include "SketcherPrs_Tools.h" @@ -14,6 +27,7 @@ #include #include +#include #include #include @@ -69,7 +83,8 @@ ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName std::shared_ptr getShape(ObjectPtr theObject) { ResultConstructionPtr aRes = std::dynamic_pointer_cast(theObject); - if (aRes.get() != NULL && aRes->data()->isValid()) {/// essential check as it is called in openGl thread + if (aRes.get() != NULL && aRes->data()->isValid()) { + /// essential check as it is called in openGl thread return aRes->shape(); } return std::shared_ptr(); @@ -87,13 +102,13 @@ std::shared_ptr getPoint(ModelAPI_Feature* theFeature, } //************************************************************************************* -/// Find an attribute of the given object which corresponds to a vetrex +/// Find an attribute of the given object which corresponds to a vetrex /// defined by a shape /// \param theObject an object /// \param theShape a vertex /// \param thePlane a projection plane (sketcher plane) -std::shared_ptr findGeomPoint(ObjectPtr theObject, - const TopoDS_Shape& theShape, +std::shared_ptr findGeomPoint(ObjectPtr theObject, + const TopoDS_Shape& theShape, const std::shared_ptr& thePlane) { std::shared_ptr aGeomPoint; @@ -108,12 +123,12 @@ std::shared_ptr findGeomPoint(ObjectPtr theObject, new GeomAPI_Pnt(aShapePoint.X(), aShapePoint.Y(), aShapePoint.Z())); // find the given point in the feature attributes - std::list anObjectAttiributes = + std::list anObjectAttiributes = anObjectFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); - std::list::const_iterator anIt = anObjectAttiributes.begin(), + std::list::const_iterator anIt = anObjectAttiributes.begin(), aLast = anObjectAttiributes.end(); for (; anIt != aLast && !aGeomPoint; anIt++) { - std::shared_ptr anAttributePoint = + std::shared_ptr anAttributePoint = std::dynamic_pointer_cast(*anIt); std::shared_ptr anAttributePnt = thePlane->to3D(anAttributePoint->x(), @@ -172,6 +187,49 @@ std::shared_ptr getFeaturePoint(DataPtr theData, return aPointAttr; } +//************************************************************************************* +std::list getFreePoints(const CompositeFeaturePtr& theSketch) +{ + std::list aFreePoints; + if (!theSketch) + return aFreePoints; + + AttributeRefListPtr aFeatures = theSketch->reflist(SketchPlugin_Sketch::FEATURES_ID()); + if (!aFeatures) + return aFreePoints; + std::list anObjects = aFeatures->list(); + for (std::list::iterator anObjIt = anObjects.begin(); + anObjIt != anObjects.end(); ++anObjIt) { + FeaturePtr aCurrent = ModelAPI_Feature::feature(*anObjIt); + if (aCurrent && aCurrent->getKind() == SketchPlugin_Point::ID()) { + // check point is not referred by any constraints: the feature and result of point + bool aIsFree = true; + for(int aKind = 0; aIsFree && aKind < 2; aKind++) { // 0 for feature, 1 for result + ObjectPtr aReferenced = aCurrent; + if (aKind == 1) + if (!aCurrent->results().empty()) + aReferenced = aCurrent->firstResult(); + else + break; + const std::set& aRefs = aReferenced->data()->refsToMe(); + std::set::iterator aRIt = aRefs.begin(); + for (; aRIt != aRefs.end(); ++aRIt) { + FeaturePtr aRefFeat = ModelAPI_Feature::feature((*aRIt)->owner()); + std::shared_ptr aRefConstr = + std::dynamic_pointer_cast(aRefFeat); + if (aRefConstr) { + aIsFree = false; + break; + } + } + } + if (aIsFree) + aFreePoints.push_back(aCurrent->lastResult()); + } + } + return aFreePoints; +} + //************************************************************************************* FeaturePtr getFeatureLine(DataPtr theData, const std::string& theAttribute) @@ -180,7 +238,7 @@ FeaturePtr getFeatureLine(DataPtr theData, if (!theData.get() || !theData->isValid()) /// essential check as it is called in openGl thread) return aLine; - std::shared_ptr anAttr = + std::shared_ptr anAttr = std::dynamic_pointer_cast(theData->attribute(theAttribute)); if (anAttr) { FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object()); @@ -208,8 +266,20 @@ std::shared_ptr getProjectionPoint(const FeaturePtr theLine, return aLin2d.project(thePoint); } +static int MyPixelRatio = 1; + +void setPixelRatio(int theRatio) +{ + MyPixelRatio = theRatio; +} + +int pixelRatio() +{ + return MyPixelRatio; +} static double MyArrowSize = 20; + double getArrowSize() { return MyArrowSize; @@ -225,10 +295,15 @@ int getDefaultArrowSize() return 20; } +int getConfigArrowSize() +{ + return Config_PropManager::integer("Visualization", "dimension_arrow_size"); +} + static double MyTextHeight = 16; double getTextHeight() { - return MyTextHeight; + return MyTextHeight * MyPixelRatio; } void setTextHeight(double theHeight) @@ -238,15 +313,23 @@ void setTextHeight(double theHeight) double getDefaultTextHeight() { - return 16; + return 16 * MyPixelRatio; +} + +double getConfigTextHeight() +{ + return Config_PropManager::integer("Visualization", "dimension_value_size") * MyPixelRatio; } double getFlyoutDistance(const ModelAPI_Feature* theConstraint) { std::shared_ptr aFlyoutPoint = std::dynamic_pointer_cast( - const_cast(theConstraint)->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - + const_cast( + theConstraint)->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + // for not initialized values return zero distance to avoid Presentation crash + if (!aFlyoutPoint->isInitialized()) + return 0; return aFlyoutPoint->y(); } @@ -267,7 +350,7 @@ std::shared_ptr getAnchorPoint(const ModelAPI_Feature* theConstrain } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) { // circle aCenter = std::dynamic_pointer_cast( aFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->pnt(); - } else + } else return std::shared_ptr(); std::shared_ptr anOrigin(new GeomAPI_Pnt2d(0.0, 0.0)); @@ -293,41 +376,10 @@ void sendExpressionShownEvent(const bool& theState) Events_Loop::loop()->flush(anId); } -Handle(Prs3d_DimensionAspect) createDimensionAspect() -{ - Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); - anAspect->MakeArrows3d(false); - anAspect->MakeText3d(false); - anAspect->MakeTextShaded(false); - anAspect->MakeUnitsDisplayed(false); - anAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight()); - anAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize()); - - return anAspect; -} - -void updateArrows(Handle(Prs3d_DimensionAspect) theDimAspect, double theDimValue, double theTextSize) -{ - double anArrowLength = theDimAspect->ArrowAspect()->Length(); - // This is not realy correct way to get viewer scale. - double aViewerScale = (double) SketcherPrs_Tools::getDefaultArrowSize() / anArrowLength; - - if(theTextSize > ((theDimValue - 3 * SketcherPrs_Tools::getArrowSize()) * aViewerScale)) { - theDimAspect->SetTextHorizontalPosition(Prs3d_DTHP_Left); - theDimAspect->SetArrowOrientation(Prs3d_DAO_External); - theDimAspect->SetExtensionSize((theTextSize / aViewerScale + SketcherPrs_Tools::getArrowSize()) / 2.0); - } else { - theDimAspect->SetTextHorizontalPosition(Prs3d_DTHP_Center); - theDimAspect->SetArrowOrientation(Prs3d_DAO_Internal); - } - theDimAspect->SetArrowTailSize(theDimAspect->ArrowAspect()->Length()); - // The value of vertical aligment is sometimes changed - theDimAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER); -} - void sendEmptyPresentationError(ModelAPI_Feature* theFeature, const std::string theError) { - Events_InfoMessage("SketcherPrs_Tools", "An empty AIS presentation: SketcherPrs_LengthDimension").send(); + Events_InfoMessage("SketcherPrs_Tools", + "An empty AIS presentation: SketcherPrs_LengthDimension").send(); static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION); std::shared_ptr aConstraintPtr(theFeature); ModelAPI_EventCreator::get()->sendUpdated(aConstraintPtr, anEvent);