X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_Tools.cpp;h=7947c38a2c909bf475f9f5a4577527716adf0392;hb=4a28151d74257f3a0d07af1b2270b76105e27e62;hp=912ea14467ee32d7c7b9fecd0c925422e72d2a6e;hpb=705438fb7ab16ba1608b6b1aeddd546d6311cb77;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 912ea1446..7947c38a2 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -15,6 +15,9 @@ #include #include #include +#include + +#include #include #include @@ -23,23 +26,53 @@ #include #include +#include + #include #include +#include + +// it is not possible to use 0x2211 as summ symbol because it is not supported by +// debian Linux platform +static const Standard_ExtCharacter MyEmptySymbol(' '); +static const Standard_ExtCharacter MySigmaSymbol('=');//0x03A3); // using equal instead of sigma + namespace SketcherPrs_Tools { +AttributePtr getAttribute(ModelAPI_Feature* theFeature, const std::string& theAttrName) +{ + AttributePtr anAttribute; + if (theFeature) { + std::shared_ptr aData = theFeature->data(); + if (aData.get() && aData->isValid()) { /// essential check as it is called in openGl thread + std::shared_ptr anAttr = aData->refattr(theAttrName); + if (!anAttr->isObject()) + anAttribute = anAttr->attr(); + } + } + return anAttribute; +} + ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName) { - std::shared_ptr aData = theFeature->data(); - std::shared_ptr anAttr = aData->refattr(theAttrName); - return anAttr->object(); + ObjectPtr anObject; + if (theFeature) { + std::shared_ptr aData = theFeature->data(); + if (aData.get() && aData->isValid()) { /// essential check as it is called in openGl thread + std::shared_ptr anAttr = aData->refattr(theAttrName); + if (anAttr.get()) + anObject = anAttr->object(); + } + } + return anObject; } std::shared_ptr getShape(ObjectPtr theObject) { ResultConstructionPtr aRes = std::dynamic_pointer_cast(theObject); - if (aRes.get() != NULL) { + if (aRes.get() != NULL && aRes->data()->isValid()) {/// essential check as it is called in openGl thread return aRes->shape(); } return std::shared_ptr(); @@ -51,14 +84,17 @@ std::shared_ptr getPoint(ModelAPI_Feature* theFeature, { std::shared_ptr aPointAttr; - if (!theFeature->data()) + /// essential check as it is called in openGl thread + if (!theFeature || !theFeature->data().get() || !theFeature->data()->isValid()) return std::shared_ptr(); FeaturePtr aFeature; std::shared_ptr anAttr = std::dynamic_pointer_cast< ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute)); - if (anAttr) - aFeature = ModelAPI_Feature::feature(anAttr->object()); + if(!anAttr.get()) { + return std::shared_ptr(); + } + aFeature = ModelAPI_Feature::feature(anAttr->object()); if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) aPointAttr = std::dynamic_pointer_cast( @@ -73,6 +109,11 @@ std::shared_ptr getPoint(ModelAPI_Feature* theFeature, } //************************************************************************************* +/// 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, const std::shared_ptr& thePlane) @@ -118,7 +159,7 @@ std::shared_ptr getFeaturePoint(DataPtr theData, { std::shared_ptr aPointAttr; - if (!theData) + if (!theData.get() || !theData->isValid()) /// essential check as it is called in openGl thread return aPointAttr; FeaturePtr aFeature; @@ -129,10 +170,12 @@ std::shared_ptr getFeaturePoint(DataPtr theData, ObjectPtr anObject = anAttr->object(); aFeature = ModelAPI_Feature::feature(anObject); if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) { + // Attribute refers to a point aPointAttr = std::dynamic_pointer_cast( aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); } else { + // if the attribute refers on another object ResultPtr aRes = std::dynamic_pointer_cast(anObject); if (aRes.get()) { GeomShapePtr aShape = aRes->shape(); @@ -144,6 +187,7 @@ std::shared_ptr getFeaturePoint(DataPtr theData, } } else if (anAttr->attr()) { + // If attribute is a point aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); } } @@ -155,7 +199,7 @@ FeaturePtr getFeatureLine(DataPtr theData, const std::string& theAttribute) { FeaturePtr aLine; - if (!theData) + if (!theData.get() || !theData->isValid()) /// essential check as it is called in openGl thread) return aLine; std::shared_ptr anAttr = @@ -174,6 +218,9 @@ std::shared_ptr getProjectionPoint(const FeaturePtr theLine, const std::shared_ptr& thePoint) { DataPtr aData = theLine->data(); + if (!aData.get() || !aData->isValid()) + return std::shared_ptr(); + std::shared_ptr aPoint1 = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Line::START_ID())); std::shared_ptr aPoint2 = std::dynamic_pointer_cast( @@ -184,7 +231,7 @@ std::shared_ptr getProjectionPoint(const FeaturePtr theLine, } -static double MyArrowSize = 24.; +static double MyArrowSize = 20; double getArrowSize() { return MyArrowSize; @@ -195,6 +242,11 @@ void setArrowSize(double theSize) MyArrowSize = theSize; } +int getDefaultArrowSize() +{ + return 20; +} + static double MyTextHeight = 16; double getTextHeight() { @@ -231,13 +283,13 @@ std::shared_ptr getAnchorPoint(const ModelAPI_Feature* theConstrain FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); std::shared_ptr aCenter; - if (aFeature->getKind() == SketchPlugin_Arc::ID()) { + if (aFeature->getKind() == SketchPlugin_Arc::ID()) { // arc aCenter = std::dynamic_pointer_cast( aFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt(); - } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) { + } 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)); @@ -252,4 +304,81 @@ std::shared_ptr getAnchorPoint(const ModelAPI_Feature* theConstrain return thePlane->to3D(aFlyoutPnt->x(), aFlyoutPnt->y()); } +void setDisplaySpecialSymbol(AIS_Dimension* theDimension, const bool& theToDisplay) +{ + if (theToDisplay) { + theDimension->SetSpecialSymbol(MySigmaSymbol); + theDimension->SetDisplaySpecialSymbol(AIS_DSS_Before); + } + else { + theDimension->SetSpecialSymbol(MyEmptySymbol); + theDimension->SetDisplaySpecialSymbol(AIS_DSS_No); + } +} + +void setDisplayParameter(AIS_Dimension* theDimension, const std::string& theParameter, + const bool& theToDisplay) +{ + if (theToDisplay) { + theDimension->DimensionAspect()->MakeUnitsDisplayed(true); + theDimension->SetDisplayUnits(TCollection_AsciiString(theParameter.c_str())); + theDimension->DimensionAspect()->SetValueStringFormat(""); + } + else { + theDimension->DimensionAspect()->MakeUnitsDisplayed(false); + theDimension->SetDisplayUnits(TCollection_AsciiString()); // THE_UNDEFINED_UNITS in AIS_Dimension + theDimension->DimensionAspect()->SetValueStringFormat("%g"); + } +} + +void sendExpressionShownEvent(const bool& theState) +{ + static Events_ID anId = SketcherPrs_ParameterStyleMessage::eventId(); + std::shared_ptr aMessage = std::shared_ptr + (new SketcherPrs_ParameterStyleMessage(anId, 0)); + aMessage->setStyle(theState ? SketcherPrs_ParameterStyleMessage::ParameterText + : SketcherPrs_ParameterStyleMessage::ParameterValue); + Events_Loop::loop()->send(aMessage); + 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(); + static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION); + std::shared_ptr aConstraintPtr(theFeature); + ModelAPI_EventCreator::get()->sendUpdated(aConstraintPtr, anEvent); +} };