]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Empty AIS in the viewer: throw c++ exception (to be finalized, currently do nothing)
authornds <nds@opencascade.com>
Wed, 17 Feb 2016 15:52:06 +0000 (18:52 +0300)
committernds <nds@opencascade.com>
Wed, 17 Feb 2016 15:52:06 +0000 (18:52 +0300)
src/Events/Events_Error.cpp
src/Events/Events_Error.h
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/PartSet/PartSet_OperationPrs.cpp
src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp
src/SketcherPrs/SketcherPrs_Angle.cpp
src/SketcherPrs/SketcherPrs_Coincident.cpp
src/SketcherPrs/SketcherPrs_LengthDimension.cpp
src/SketcherPrs/SketcherPrs_Radius.cpp
src/SketcherPrs/SketcherPrs_SymbolPrs.cpp

index 4b7670e8ef55e1c54794c6880b01b4191151c7ed..c646cbf0cae5cf598a79c395c629bbc404d22d9d 100644 (file)
@@ -10,6 +10,8 @@
 #include <Events_Error.h>
 #include <Events_Loop.h>
 
+//#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<Events_Message>(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
index e288f9f55e90a5e80f2f971d03541f2861ae394d..b344c6e36f9a3319939a1d351e4247158a9d9d27 100644 (file)
@@ -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);
index 2d08104de7177a6b9487db8085a198ce39d81ba4..3b32e56eef836e75c07ed6542088306ae578a01b 100755 (executable)
@@ -11,6 +11,8 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <GeomAPI_PlanarEdges.h>
 
+#include <Events_Error.h>
+
 #include <BRep_Builder.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d.hxx>
@@ -72,8 +74,10 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
                                    const Standard_Integer theMode)
 {
   std::shared_ptr<GeomAPI_Shape> 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");
 }
 
 
index fc67747b98581b2be18c132b46655ca799c6bd50..1b4491e6d59a870e7dc7847279ab360faa75b33d 100755 (executable)
@@ -27,6 +27,8 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_ResultCompSolid.h>
 
+#include <Events_Error.h>
+
 #include <GeomAPI_IPresentable.h>
 
 #include <StdPrs_WFDeflectionShape.hxx>
@@ -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<ObjectPtr, QList<GeomShapePtr> >::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,
index 9fe7e5188793955e98975860a063f0acaf706abf..0f7aa24926376731fc126ddd956c34badf04853c 100644 (file)
@@ -14,6 +14,7 @@
 #include <SketchPlugin_Sketch.h>
 
 #include <SketcherPrs_Factory.h>
+//#include <SketcherPrs_Tools.h>
 
 #include <Config_PropManager.h>
 
@@ -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;
 }
 
index 6f5c379f3c6732c51fec2a1ed44035157aed1f15..04c7bd25e4da75d3c7147890e4142dcdb49b17dd 100644 (file)
@@ -20,6 +20,8 @@
 #include <TopExp.hxx>
 #include <BRep_Tool.hxx>
 
+#include <Events_Error.h>
+
 #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<GeomDataAPI_Point2D> aFlyoutAttr = 
     std::dynamic_pointer_cast<GeomDataAPI_Point2D>
     (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<GeomAPI_Pnt> 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<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
   std::shared_ptr<GeomAPI_Shape> 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>();
   TopoDS_Shape aTEdge2 = aShape2->impl<TopoDS_Shape>();
index f9e2e2959123b8d00fd9ce62356ada24721d7892..764a45586870526e7ddb7a374def2fc425496c17 100644 (file)
@@ -16,6 +16,8 @@
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_Pnt2d.h>
 
+#include <Events_Error.h>
+
 #include <SketchPlugin_Constraint.h>
 
 #include <Graphic3d_AspectMarker3d.hxx>
@@ -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<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
   myPoint = aPoint->impl<gp_Pnt>();
 
index eaf5ec0cd6819b875cbf09ed7b79b624b08bfcd6..49415d7bbfbb5ffa2c03f690aa75a29d23c2b818 100644 (file)
@@ -14,6 +14,8 @@
 #include <SketchPlugin_Point.h>
 #include <SketchPlugin_Circle.h>
 
+#include <Events_Error.h>
+
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_XYZ.h>
@@ -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));
index d6299a9050a39d449625d382cef9e5e27f056bd6..d26d3e539463d0e0992e7b96c9291b7674961b42 100644 (file)
@@ -12,6 +12,8 @@
 #include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Arc.h>
 
+#include <Events_Error.h>
+
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Circ.h>
@@ -52,8 +54,10 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the
   std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
     std::dynamic_pointer_cast<GeomDataAPI_Point2D>
     (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<ModelAPI_AttributeRefAttr> anAttr = 
index ab8dfeb4f19a5aab5c9b7096807287bc475a10a9..81e1f44fa43ab333796ceffd1f2e54acd8b384c1 100644 (file)
@@ -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;
   }