#include <TopExp.hxx>
#include <BRep_Tool.hxx>
+#include <Events_Error.h>
+
#define PI 3.1415926535897932
IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension);
IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension);
-
-static const Standard_ExtCharacter MyEmptySymbol(' ');
-static const Standard_ExtCharacter MySummSymbol(0x03A3);
-
SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane)
: AIS_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint), myPlane(thePlane)
SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
}
-void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
+bool SketcherPrs_Angle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
{
- DataPtr aData = myConstraint->data();
+ bool aReadyToDisplay = false;
+
+ DataPtr aData = theConstraint->data();
// Flyout point
std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
if (!aFlyoutAttr->isInitialized())
- return; // can not create a good presentation
-
- std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
+ return aReadyToDisplay; // can not create a good presentation
AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
if (!anAttr1->isInitialized())
- return;
+ return aReadyToDisplay;
AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B());
if (!anAttr2->isInitialized())
- return;
+ return aReadyToDisplay;
// Get angle edges
ObjectPtr aObj1 = anAttr1->object();
std::shared_ptr<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
std::shared_ptr<GeomAPI_Shape> aShape2 = SketcherPrs_Tools::getShape(aObj2);
- if (!aShape1 && !aShape2)
- return;
+ aReadyToDisplay = aShape1.get() && aShape2.get();
+ return aReadyToDisplay;
+}
+
+void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ DataPtr aData = myConstraint->data();
+
+ if (!IsReadyToDisplay(myConstraint, myPlane)) {
+ Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle");
+ return; // can not create a good presentation
+ }
+
+ // Flyout point
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+ std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
+
+ AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
+ AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B());
+
+ // Get angle edges
+ ObjectPtr aObj1 = anAttr1->object();
+ ObjectPtr aObj2 = anAttr2->object();
+
+ std::shared_ptr<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
+ std::shared_ptr<GeomAPI_Shape> aShape2 = SketcherPrs_Tools::getShape(aObj2);
TopoDS_Shape aTEdge1 = aShape1->impl<TopoDS_Shape>();
TopoDS_Shape aTEdge2 = aShape2->impl<TopoDS_Shape>();
myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length());
AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
- std::set<std::string> aParams = aValue->usedParameters();
- if (aParams.size() > 0) {
- SetSpecialSymbol(MySummSymbol);
- SetDisplaySpecialSymbol(AIS_DSS_Before);
- }
- else {
- SetSpecialSymbol(MyEmptySymbol);
- SetDisplaySpecialSymbol(AIS_DSS_Before);
- }
+ SketcherPrs_Tools::setDisplaySpecialSymbol(this, aValue->usedParameters().size() > 0);
AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode);
}