#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)
{
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
/// 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);
#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_PlanarEdges.h>
+#include <Events_Error.h>
+
#include <BRep_Builder.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d.hxx>
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();
ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
}
+ else
+ Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
}
#include <ModelAPI_Session.h>
#include <ModelAPI_ResultCompSolid.h>
+#include <Events_Error.h>
+
#include <GeomAPI_IPresentable.h>
#include <StdPrs_WFDeflectionShape.hxx>
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++) {
}
}
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,
#include <SketchPlugin_Sketch.h>
#include <SketcherPrs_Factory.h>
+//#include <SketcherPrs_Tools.h>
#include <Config_PropManager.h>
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;
}
#include <TopExp.hxx>
#include <BRep_Tool.hxx>
+#include <Events_Error.h>
+
#define PI 3.1415926535897932
IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension);
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();
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>();
#include <GeomAPI_Dir.h>
#include <GeomAPI_Pnt2d.h>
+#include <Events_Error.h>
+
#include <SketchPlugin_Constraint.h>
#include <Graphic3d_AspectMarker3d.hxx>
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>();
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Circle.h>
+#include <Events_Error.h>
+
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_XYZ.h>
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));
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Arc.h>
+#include <Events_Error.h>
+
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Circ.h>
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 =
// Update points with default shift value
if (!updatePoints(20)) {
+ Events_Error::throwException("An empty AIS presentation: SketcherPrs_SymbolPrs");
return;
}