-// Copyright (C) 2014-2017 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
//
// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SketcherPrs_Tools.h"
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Events.h>
#include <BRep_Tool.hxx>
#include <Precision.hxx>
-#include <AIS_Dimension.hxx>
+#include <PrsDim_Dimension.hxx>
namespace SketcherPrs_Tools {
+static ParameterStyle MyStyle = ParameterValue;
+
+void setParameterStyle(ParameterStyle theStyle)
+{
+ MyStyle = theStyle;
+}
+
+ParameterStyle parameterStyle()
+{
+ return MyStyle;
+}
+
AttributePtr getAttribute(ModelAPI_Feature* theFeature, const std::string& theAttrName)
{
AttributePtr anAttribute;
std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject)
{
ResultConstructionPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
+ if (!aRes.get()) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aFeature.get())
+ aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aFeature->lastResult());
+ }
if (aRes.get() != NULL && aRes->data()->isValid()) {
/// essential check as it is called in openGl thread
return aRes->shape();
std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
const std::string& theAttribute)
{
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = ModelGeomAlgo_Point2D::getPointOfRefAttr(
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->attribute(theAttribute));
+ if (!aPointAttr.get() || !aPointAttr->isInitialized()) {
+ aPointAttr = ModelGeomAlgo_Point2D::getPointOfRefAttr(
theFeature, theAttribute, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
+ }
if (aPointAttr.get() != NULL)
return aPointAttr->pnt();
return std::shared_ptr<GeomAPI_Pnt2d>();
return aPointAttr;
}
+//*************************************************************************************
+std::list<ResultPtr> getFreePoints(const CompositeFeaturePtr& theSketch)
+{
+ std::list<ResultPtr> aFreePoints;
+ if (!theSketch)
+ return aFreePoints;
+
+ AttributeRefListPtr aFeatures = theSketch->reflist(SketchPlugin_Sketch::FEATURES_ID());
+ if (!aFeatures)
+ return aFreePoints;
+ std::list<ObjectPtr> anObjects = aFeatures->list();
+ for (std::list<ObjectPtr>::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<AttributePtr>& aRefs = aReferenced->data()->refsToMe();
+ std::set<AttributePtr>::iterator aRIt = aRefs.begin();
+ for (; aRIt != aRefs.end(); ++aRIt) {
+ FeaturePtr aRefFeat = ModelAPI_Feature::feature((*aRIt)->owner());
+ std::shared_ptr<SketchPlugin_Constraint> aRefConstr =
+ std::dynamic_pointer_cast<SketchPlugin_Constraint>(aRefFeat);
+ if (aRefConstr) {
+ aIsFree = false;
+ break;
+ }
+ }
+ }
+ if (aIsFree)
+ aFreePoints.push_back(aCurrent->lastResult());
+ }
+ }
+ return aFreePoints;
+}
+
//*************************************************************************************
FeaturePtr getFeatureLine(DataPtr theData,
const std::string& theAttribute)
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;
static double MyTextHeight = 16;
double getTextHeight()
{
- return MyTextHeight;
+ return MyTextHeight * MyPixelRatio;
}
void setTextHeight(double theHeight)
double getDefaultTextHeight()
{
- return 16;
+ return 16 * MyPixelRatio;
}
double getConfigTextHeight()
{
- return Config_PropManager::integer("Visualization", "dimension_value_size");
+ return Config_PropManager::integer("Visualization", "dimension_value_size") * MyPixelRatio;
}
double getFlyoutDistance(const ModelAPI_Feature* theConstraint)
return thePlane->to3D(aFlyoutPnt->x(), aFlyoutPnt->y());
}
-void sendExpressionShownEvent(const bool& theState)
-{
- static Events_ID anId = SketcherPrs_ParameterStyleMessage::eventId();
- std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::shared_ptr
- <SketcherPrs_ParameterStyleMessage>(new SketcherPrs_ParameterStyleMessage(anId, 0));
- aMessage->setStyle(theState ? SketcherPrs_ParameterStyleMessage::ParameterText
- : SketcherPrs_ParameterStyleMessage::ParameterValue);
- Events_Loop::loop()->send(aMessage);
- Events_Loop::loop()->flush(anId);
-}
-
void sendEmptyPresentationError(ModelAPI_Feature* theFeature, const std::string theError)
{
Events_InfoMessage("SketcherPrs_Tools",