Replace Base::Exception with appropriate subclass
This commit is contained in:
@@ -224,6 +224,50 @@ const char* BRepBuilderAPI_FaceErrorText(BRepBuilderAPI_FaceError et)
|
||||
|
||||
// ------------------------------------------------
|
||||
|
||||
NullShapeException::NullShapeException()
|
||||
: ValueError()
|
||||
{
|
||||
}
|
||||
|
||||
NullShapeException::NullShapeException(const char * sMessage)
|
||||
: ValueError(sMessage)
|
||||
{
|
||||
}
|
||||
|
||||
NullShapeException::NullShapeException(const std::string& sMessage)
|
||||
: ValueError(sMessage)
|
||||
{
|
||||
}
|
||||
|
||||
NullShapeException::NullShapeException(const NullShapeException &inst)
|
||||
: ValueError(inst)
|
||||
{
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
|
||||
BooleanException::BooleanException()
|
||||
: CADKernelError()
|
||||
{
|
||||
}
|
||||
|
||||
BooleanException::BooleanException(const char * sMessage)
|
||||
: CADKernelError(sMessage)
|
||||
{
|
||||
}
|
||||
|
||||
BooleanException::BooleanException(const std::string& sMessage)
|
||||
: CADKernelError(sMessage)
|
||||
{
|
||||
}
|
||||
|
||||
BooleanException::BooleanException(const BooleanException &inst)
|
||||
: CADKernelError(inst)
|
||||
{
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::ShapeSegment , Data::Segment);
|
||||
|
||||
std::string ShapeSegment::getName() const
|
||||
@@ -233,7 +277,7 @@ std::string ShapeSegment::getName() const
|
||||
|
||||
// ------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::TopoShape , Data::ComplexGeoData);
|
||||
TYPESYSTEM_SOURCE(Part::TopoShape , Data::ComplexGeoData)
|
||||
|
||||
TopoShape::TopoShape()
|
||||
{
|
||||
@@ -489,7 +533,7 @@ void TopoShape::read(const char *FileName)
|
||||
importBrep(File.filePath().c_str());
|
||||
}
|
||||
else{
|
||||
throw Base::Exception("Unknown extension");
|
||||
throw Base::FileException("Unknown extension");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,7 +581,7 @@ void TopoShape::importIges(const char *FileName)
|
||||
// http://www.opencascade.org/org/forum/thread_20603/?forum=3
|
||||
aReader.SetReadVisible(Standard_True);
|
||||
if (aReader.ReadFile(encodeFilename(FileName).c_str()) != IFSelect_RetDone)
|
||||
throw Base::Exception("Error in reading IGES");
|
||||
throw Base::FileException("Error in reading IGES");
|
||||
|
||||
Handle(Message_ProgressIndicator) pi = new ProgressIndicator(100);
|
||||
pi->NewScope(100, "Reading IGES file...");
|
||||
@@ -552,7 +596,7 @@ void TopoShape::importIges(const char *FileName)
|
||||
pi->EndScope();
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
throw Base::Exception(e.GetMessageString());
|
||||
throw Base::CADKernelError(e.GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,7 +605,7 @@ void TopoShape::importStep(const char *FileName)
|
||||
try {
|
||||
STEPControl_Reader aReader;
|
||||
if (aReader.ReadFile(encodeFilename(FileName).c_str()) != IFSelect_RetDone)
|
||||
throw Base::Exception("Error in reading STEP");
|
||||
throw Base::FileException("Error in reading STEP");
|
||||
|
||||
Handle(Message_ProgressIndicator) pi = new ProgressIndicator(100);
|
||||
aReader.WS()->MapReader()->SetProgress(pi);
|
||||
@@ -575,7 +619,7 @@ void TopoShape::importStep(const char *FileName)
|
||||
pi->EndScope();
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
throw Base::Exception(e.GetMessageString());
|
||||
throw Base::CADKernelError(e.GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,7 +641,7 @@ void TopoShape::importBrep(const char *FileName)
|
||||
this->_Shape = aShape;
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
throw Base::Exception(e.GetMessageString());
|
||||
throw Base::CADKernelError(e.GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,10 +666,10 @@ void TopoShape::importBrep(std::istream& str, int indicator)
|
||||
this->_Shape = aShape;
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
throw Base::Exception(e.GetMessageString());
|
||||
throw Base::CADKernelError(e.GetMessageString());
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw Base::Exception(e.what());
|
||||
throw Base::CADKernelError(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,7 +716,7 @@ void TopoShape::write(const char *FileName) const
|
||||
exportStl(File.filePath().c_str(),0);
|
||||
}
|
||||
else{
|
||||
throw Base::Exception("Unknown extension");
|
||||
throw Base::FileException("Unknown extension");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,10 +734,10 @@ void TopoShape::exportIges(const char *filename) const
|
||||
aWriter.AddShape(this->_Shape);
|
||||
aWriter.ComputeModel();
|
||||
if (aWriter.Write(encodeFilename(filename).c_str()) != IFSelect_RetDone)
|
||||
throw Base::Exception("Writing of IGES failed");
|
||||
throw Base::FileException("Writing of IGES failed");
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
throw Base::Exception(e.GetMessageString());
|
||||
throw Base::CADKernelError(e.GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -711,7 +755,7 @@ void TopoShape::exportStep(const char *filename) const
|
||||
pi->Show();
|
||||
|
||||
if (aWriter.Transfer(this->_Shape, STEPControl_AsIs) != IFSelect_RetDone)
|
||||
throw Base::Exception("Error in transferring STEP");
|
||||
throw Base::FileException("Error in transferring STEP");
|
||||
|
||||
APIHeaderSection_MakeHeader makeHeader(aWriter.Model());
|
||||
makeHeader.SetName(new TCollection_HAsciiString((Standard_CString)(encodeFilename(filename).c_str())));
|
||||
@@ -721,18 +765,18 @@ void TopoShape::exportStep(const char *filename) const
|
||||
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
||||
|
||||
if (aWriter.Write(encodeFilename(filename).c_str()) != IFSelect_RetDone)
|
||||
throw Base::Exception("Writing of STEP failed");
|
||||
throw Base::FileException("Writing of STEP failed");
|
||||
pi->EndScope();
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
throw Base::Exception(e.GetMessageString());
|
||||
throw Base::CADKernelError(e.GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
void TopoShape::exportBrep(const char *filename) const
|
||||
{
|
||||
if (!BRepTools::Write(this->_Shape,encodeFilename(filename).c_str()))
|
||||
throw Base::Exception("Writing of BREP failed");
|
||||
throw Base::FileException("Writing of BREP failed");
|
||||
}
|
||||
|
||||
void TopoShape::exportBrep(std::ostream& out) const
|
||||
@@ -1593,7 +1637,7 @@ TopoDS_Shape TopoShape::fuse(const std::vector<TopoDS_Shape>& shapes, Standard_R
|
||||
throw Base::ValueError("Object shape is null");
|
||||
for (std::vector<TopoDS_Shape>::const_iterator it = shapes.begin(); it != shapes.end(); ++it) {
|
||||
if (it->IsNull())
|
||||
throw Base::Exception("Input shape is null");
|
||||
throw NullShapeException("Input shape is null");
|
||||
// Let's call algorithm computing a fuse operation:
|
||||
BRepAlgoAPI_Fuse mkFuse(resShape, *it);
|
||||
// Let's check if the fusion has been successful
|
||||
@@ -1610,7 +1654,7 @@ TopoDS_Shape TopoShape::fuse(const std::vector<TopoDS_Shape>& shapes, Standard_R
|
||||
shapeArguments.Append(this->_Shape);
|
||||
for (std::vector<TopoDS_Shape>::const_iterator it = shapes.begin(); it != shapes.end(); ++it) {
|
||||
if (it->IsNull())
|
||||
throw Base::Exception("Tool shape is null");
|
||||
throw NullShapeException("Tool shape is null");
|
||||
if (tolerance > 0.0)
|
||||
// workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520
|
||||
shapeTools.Append(BRepBuilderAPI_Copy(*it).Shape());
|
||||
@@ -1752,7 +1796,7 @@ TopoDS_Shape TopoShape::generalFuse(const std::vector<TopoDS_Shape> &sOthers, St
|
||||
GFAArguments.Append(this->_Shape);
|
||||
for (const TopoDS_Shape &it: sOthers) {
|
||||
if (it.IsNull())
|
||||
throw Base::Exception("Tool shape is null");
|
||||
throw NullShapeException("Tool shape is null");
|
||||
if (tolerance > 0.0)
|
||||
// workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520
|
||||
GFAArguments.Append(BRepBuilderAPI_Copy(it).Shape());
|
||||
@@ -1767,7 +1811,7 @@ TopoDS_Shape TopoShape::generalFuse(const std::vector<TopoDS_Shape> &sOthers, St
|
||||
#endif
|
||||
mkGFA.Build();
|
||||
if (!mkGFA.IsDone())
|
||||
throw Base::Exception("MultiFusion failed");
|
||||
throw BooleanException("MultiFusion failed");
|
||||
TopoDS_Shape resShape = mkGFA.Shape();
|
||||
if (mapInOut){
|
||||
for(TopTools_ListIteratorOfListOfShape it(GFAArguments); it.More(); it.Next()){
|
||||
@@ -2546,7 +2590,7 @@ TopoDS_Shape TopoShape::makeOffset2D(double offset, short joinType, bool fill, b
|
||||
builder.Add(compoundSourceWires, w);
|
||||
BRepLib_FindSurface planefinder(compoundSourceWires, -1, Standard_True);
|
||||
if (!planefinder.Found())
|
||||
throw Base::Exception("makeOffset2D: wires are nonplanar or noncoplanar");
|
||||
throw Base::CADKernelError("makeOffset2D: wires are nonplanar or noncoplanar");
|
||||
if (haveFaces){
|
||||
//extract plane from first face (useful for preserving the plane of face precisely if dealing with only one face)
|
||||
workingPlane = BRepAdaptor_Surface(TopoDS::Face(shapesToProcess[0])).Plane();
|
||||
@@ -2577,12 +2621,12 @@ TopoDS_Shape TopoShape::makeOffset2D(double offset, short joinType, bool fill, b
|
||||
throw;
|
||||
}
|
||||
catch (...) {
|
||||
throw Base::Exception("BRepOffsetAPI_MakeOffset has crashed! (Unknown exception caught)");
|
||||
throw Base::CADKernelError("BRepOffsetAPI_MakeOffset has crashed! (Unknown exception caught)");
|
||||
}
|
||||
offsetShape = mkOffset.Shape();
|
||||
|
||||
if(offsetShape.IsNull())
|
||||
throw Base::Exception("makeOffset2D: result of offsetting is null!");
|
||||
throw Base::CADKernelError("makeOffset2D: result of offsetting is null!");
|
||||
|
||||
//Copying shape to fix strange orientation behavior, OCC7.0.0. See bug #2699
|
||||
// http://www.freecadweb.org/tracker/view.php?id=2699
|
||||
@@ -2601,7 +2645,7 @@ TopoDS_Shape TopoShape::makeOffset2D(double offset, short joinType, bool fill, b
|
||||
}
|
||||
|
||||
if (offsetWires.empty())
|
||||
throw Base::Exception("makeOffset2D: offset result has no wires.");
|
||||
throw Base::CADKernelError("makeOffset2D: offset result has no wires.");
|
||||
|
||||
std::list<TopoDS_Wire> wiresForMakingFaces;
|
||||
if (!fill){
|
||||
@@ -2650,7 +2694,7 @@ TopoDS_Shape TopoShape::makeOffset2D(double offset, short joinType, bool fill, b
|
||||
|
||||
//for now, only support offsetting one open wire -> there should be exactly two open wires for connecting
|
||||
if (openWires.size() != 2)
|
||||
throw Base::Exception("makeOffset2D: collective offset with filling of multiple wires is not supported yet.");
|
||||
throw Base::CADKernelError("makeOffset2D: collective offset with filling of multiple wires is not supported yet.");
|
||||
|
||||
TopoDS_Wire openWire1 = openWires.front();
|
||||
TopoDS_Wire openWire2 = openWires.back();
|
||||
@@ -2669,10 +2713,10 @@ TopoDS_Shape TopoShape::makeOffset2D(double offset, short joinType, bool fill, b
|
||||
TopoDS_Vertex v4 = xp.CurrentVertex();
|
||||
|
||||
//check
|
||||
if (v1.IsNull()) throw Base::Exception("v1 is null");
|
||||
if (v2.IsNull()) throw Base::Exception("v2 is null");
|
||||
if (v3.IsNull()) throw Base::Exception("v3 is null");
|
||||
if (v4.IsNull()) throw Base::Exception("v4 is null");
|
||||
if (v1.IsNull()) throw NullShapeException("v1 is null");
|
||||
if (v2.IsNull()) throw NullShapeException("v2 is null");
|
||||
if (v3.IsNull()) throw NullShapeException("v3 is null");
|
||||
if (v4.IsNull()) throw NullShapeException("v4 is null");
|
||||
|
||||
//assemble new wire
|
||||
|
||||
@@ -2688,7 +2732,7 @@ TopoDS_Shape TopoShape::makeOffset2D(double offset, short joinType, bool fill, b
|
||||
} else if ((fabs(gp_Vec(BRep_Tool::Pnt(v2), BRep_Tool::Pnt(v4)).Magnitude() - fabs(offset)) <= BRep_Tool::Tolerance(v2) + BRep_Tool::Tolerance(v4))){
|
||||
//orientation is as expected, nothing to do
|
||||
} else {
|
||||
throw Base::Exception("makeOffset2D: fill offset: failed to establish open vertex relationship.");
|
||||
throw Base::CADKernelError("makeOffset2D: fill offset: failed to establish open vertex relationship.");
|
||||
}
|
||||
|
||||
//now directions of open wires are aligned. Finally. make new wire!
|
||||
@@ -2723,7 +2767,7 @@ TopoDS_Shape TopoShape::makeOffset2D(double offset, short joinType, bool fill, b
|
||||
}
|
||||
mkFace.Build();
|
||||
if (mkFace.Shape().IsNull())
|
||||
throw Base::Exception("makeOffset2D: making face failed (null shape returned).");
|
||||
throw Base::CADKernelError("makeOffset2D: making face failed (null shape returned).");
|
||||
TopoDS_Shape result = mkFace.Shape();
|
||||
if (haveFaces && shapesToProcess.size() == 1)
|
||||
result.Orientation(shapesToProcess[0].Orientation());
|
||||
|
||||
Reference in New Issue
Block a user