From: nds Date: Wed, 17 Feb 2016 15:52:06 +0000 (+0300) Subject: Empty AIS in the viewer: throw c++ exception (to be finalized, currently do nothing) X-Git-Tag: V_2.2.0~107 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5cd5c63e95c048ef98621e15929c1e95ad580b24;p=modules%2Fshaper.git Empty AIS in the viewer: throw c++ exception (to be finalized, currently do nothing) --- diff --git a/src/Events/Events_Error.cpp b/src/Events/Events_Error.cpp index 4b7670e8e..c646cbf0c 100644 --- a/src/Events/Events_Error.cpp +++ b/src/Events/Events_Error.cpp @@ -10,6 +10,8 @@ #include #include +//#define TROW_EMPTY_AIS_EXCEPTION + Events_Error::Events_Error(const std::string& theDescription, const void* theSender) : Events_Message(Events_Error::errorID(), theSender) { @@ -37,3 +39,16 @@ void Events_Error::send(const std::string& theDescription, const void* theSender std::shared_ptr(new Events_Error(theDescription, theSender)); Events_Loop::loop()->send(aNewOne); } + +void Events_Error::throwException(const std::string& theDescription) +{ +#ifdef TROW_EMPTY_AIS_EXCEPTION + try { + throw std::invalid_argument(theDescription); + } + catch (...) { + Events_Error::send( + std::string("An exception: ") + theDescription); + } +#endif +} \ No newline at end of file diff --git a/src/Events/Events_Error.h b/src/Events/Events_Error.h index e288f9f55..b344c6e36 100644 --- a/src/Events/Events_Error.h +++ b/src/Events/Events_Error.h @@ -37,6 +37,10 @@ public: /// Allows to send an error quickly: it creates and sends the error object automatically EVENTS_EXPORT static void send(const std::string& theDescription, const void* theSender = 0); + /// Throws a C++ exception about using an empty AIS object + /// \theDescription an exception information + EVENTS_EXPORT static void throwException(const std::string& theDescription); + protected: /// Default constructor. Use "send" message for generation an error. EVENTS_EXPORT Events_Error(const std::string& theDescription, const void* theSender = 0); diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 2d08104de..3b32e56ee 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -11,6 +11,8 @@ #include #include +#include + #include #include #include @@ -72,8 +74,10 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t const Standard_Integer theMode) { std::shared_ptr aShapePtr = ModelAPI_Tools::shape(myResult); - if (!aShapePtr) + if (!aShapePtr) { + Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs"); return; + } if (myIsSketchMode) { myFacesList.clear(); @@ -94,6 +98,8 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes()); AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); } + else + Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs"); } diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index fc67747b9..1b4491e6d 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -27,6 +27,8 @@ #include #include +#include + #include #include @@ -70,6 +72,7 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t Handle(Prs3d_Drawer) aDrawer = Attributes(); // create presentations on the base of the shapes + bool anEmptyAIS = true; QMap >::const_iterator anIt = myFeatureShapes.begin(), aLast = myFeatureShapes.end(); for (; anIt != aLast; anIt++) { @@ -102,8 +105,12 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t } } StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer); + if (anEmptyAIS) + anEmptyAIS = false; } } + if (anEmptyAIS) + Events_Error::throwException("An empty AIS presentation: PartSet_OperationPrs"); } void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, diff --git a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp index 9fe7e5188..0f7aa2492 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp @@ -14,6 +14,7 @@ #include #include +//#include #include @@ -36,9 +37,21 @@ AISObjectPtr SketchPlugin_ConstraintHorizontal::getAISObject(AISObjectPtr thePre return thePrevious; AISObjectPtr anAIS = thePrevious; + if (!anAIS) { anAIS = SketcherPrs_Factory::horisontalConstraint(this, sketch()->coordinatePlane()); + /* + ObjectPtr aObj = SketcherPrs_Tools::getResult(this, SketchPlugin_Constraint::ENTITY_A()); + if (SketcherPrs_Tools::getShape(aObj).get() != NULL) { + anAIS = SketcherPrs_Factory::horisontalConstraint(this, sketch()->coordinatePlane()); + }*/ } + /*else { + ObjectPtr aObj = SketcherPrs_Tools::getResult(this, SketchPlugin_Constraint::ENTITY_A()); + if (SketcherPrs_Tools::getShape(aObj).get() == NULL) { + anAIS = AISObjectPtr(); + } + }*/ return anAIS; } diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp index 6f5c379f3..04c7bd25e 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.cpp +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -20,6 +20,8 @@ #include #include +#include + #define PI 3.1415926535897932 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension); @@ -51,19 +53,23 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - if (!aFlyoutAttr->isInitialized()) + if (!aFlyoutAttr->isInitialized()) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); return; // can not create a good presentation - + } std::shared_ptr aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); - if (!anAttr1->isInitialized()) + if (!anAttr1->isInitialized()) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); return; + } AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); - if (!anAttr2->isInitialized()) + if (!anAttr2->isInitialized()) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); return; - + } // Get angle edges ObjectPtr aObj1 = anAttr1->object(); ObjectPtr aObj2 = anAttr2->object(); @@ -71,8 +77,10 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP std::shared_ptr aShape1 = SketcherPrs_Tools::getShape(aObj1); std::shared_ptr aShape2 = SketcherPrs_Tools::getShape(aObj2); - if (!aShape1 && !aShape2) + if (!aShape1 && !aShape2) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); return; + } TopoDS_Shape aTEdge1 = aShape1->impl(); TopoDS_Shape aTEdge2 = aShape2->impl(); diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index f9e2e2959..764a45586 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -16,6 +16,8 @@ #include #include +#include + #include #include @@ -48,9 +50,10 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& SketchPlugin_Constraint::ENTITY_A()); if (aPnt.get() == NULL) aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - if (aPnt.get() == NULL) + if (aPnt.get() == NULL) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Coincident"); return; - + } std::shared_ptr aPoint = myPlane->to3D(aPnt->x(), aPnt->y()); myPoint = aPoint->impl(); diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index eaf5ec0cd..49415d7bb 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include #include #include @@ -56,8 +58,10 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage const Standard_Integer theMode) { gp_Pnt aPnt1, aPnt2; - if (!getPoints(aPnt1, aPnt2)) + if (!getPoints(aPnt1, aPnt2)) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension"); return; + } // compute flyout distance SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint)); diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index d6299a905..d26d3e539 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -12,6 +12,8 @@ #include #include +#include + #include #include #include @@ -52,8 +54,10 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - if (!aFlyoutAttr->isInitialized()) + if (!aFlyoutAttr->isInitialized()) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Radius"); return; // can not create a good presentation + } // Get circle std::shared_ptr anAttr = diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index ab8dfeb4f..81e1f44fa 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -365,6 +365,7 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& // Update points with default shift value if (!updatePoints(20)) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_SymbolPrs"); return; }