Fix crashes of Sketcher and Import/Export

This commit is contained in:
jfa 2005-08-19 09:11:52 +00:00
parent 150ae46477
commit a8a220072b
8 changed files with 135 additions and 145 deletions

View File

@ -472,13 +472,13 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
* MakeSketcher
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
(const TCollection_AsciiString& theCommand,
list<double> theWorkingPlane)
{
SetErrorCode(KO);
if (!theCommand) return NULL;
if (strcmp(theCommand, "") == 0) return NULL;
if (theCommand.IsEmpty()) return NULL;
//Add a new Sketcher object
Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
@ -493,8 +493,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCom
GEOMImpl_ISketcher aCI (aFunction);
TCollection_AsciiString aCommand ((char*) theCommand);
aCI.SetCommand(aCommand);
aCI.SetCommand(theCommand);
int ind = 1;
list<double>::iterator it = theWorkingPlane.begin();
@ -516,7 +515,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCom
//Make a Python command
GEOM::TPythonDump pd (aFunction);
pd << aSketcher << " = geompy.MakeSketcher(\"" << theCommand << "\", [";
pd << aSketcher << " = geompy.MakeSketcher(\"" << theCommand.ToCString() << "\", [";
it = theWorkingPlane.begin();
pd << (*it++);
@ -534,13 +533,13 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCom
* MakeSketcherOnPlane
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane (const char* theCommand,
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
(const TCollection_AsciiString& theCommand,
Handle(GEOM_Object) theWorkingPlane)
{
SetErrorCode(KO);
if (!theCommand) return NULL;
if (strcmp(theCommand, "") == 0) return NULL;
if (theCommand.IsEmpty()) return NULL;
//Add a new Sketcher object
Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
@ -554,9 +553,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane (const char*
if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
GEOMImpl_ISketcher aCI (aFunction);
TCollection_AsciiString aCommand ((char*) theCommand);
aCI.SetCommand(aCommand);
aCI.SetCommand(theCommand);
Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
if (aRefPlane.IsNull()) return NULL;
@ -577,7 +574,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane (const char*
//Make a Python command
GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
<< theCommand << "\", " << theWorkingPlane << " )";
<< theCommand.ToCString() << "\", " << theWorkingPlane << " )";
SetErrorCode(OK);
return aSketcher;

View File

@ -5,6 +5,8 @@ using namespace std;
#include "GEOM_IOperations.hxx"
#include <TCollection_AsciiString.hxx>
#include <list>
class GEOM_Engine;
@ -34,8 +36,9 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations {
Standard_EXPORT Handle(GEOM_Object) MakeSplineBezier (list<Handle(GEOM_Object)> thePoints);
Standard_EXPORT Handle(GEOM_Object) MakeSplineInterpolation (list<Handle(GEOM_Object)> thePoints);
Standard_EXPORT Handle(GEOM_Object) MakeSketcher (const char* theCommand, list<double> theWorkingPlane);
Standard_EXPORT Handle(GEOM_Object) MakeSketcherOnPlane (const char* theCommand,
Standard_EXPORT Handle(GEOM_Object) MakeSketcher (const TCollection_AsciiString& theCommand,
list<double> theWorkingPlane);
Standard_EXPORT Handle(GEOM_Object) MakeSketcherOnPlane (const TCollection_AsciiString& theCommand,
Handle(GEOM_Object) theWorkingPlane);
};

View File

@ -104,8 +104,8 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) the
//=============================================================================
void GEOMImpl_IInsertOperations::Export
(const Handle(GEOM_Object) theOriginal,
const char* theFileName,
const char* theFormatName)
const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatName)
{
SetErrorCode(KO);
@ -124,12 +124,10 @@ void GEOMImpl_IInsertOperations::Export
//Set parameters
GEOMImpl_IImportExport aCI (aFunction);
aCI.SetOriginal(aRefFunction);
char* aFileName = (char*)theFileName;
aCI.SetFileName(aFileName);
aCI.SetFileName(theFileName);
char* aFormatName = (char*)theFormatName;
Handle(TCollection_HAsciiString) aHLibName;
if (!IsSupported(Standard_False, aFormatName, aHLibName)) {
if (!IsSupported(Standard_False, theFormatName, aHLibName)) {
return;
}
TCollection_AsciiString aLibName = aHLibName->String();
@ -149,8 +147,8 @@ void GEOMImpl_IInsertOperations::Export
}
//Make a Python command
GEOM::TPythonDump(aFunction) << "geompy.Export(" << theOriginal
<< ", \"" << theFileName << "\", \"" << theFormatName << "\")";
GEOM::TPythonDump(aFunction) << "geompy.Export(" << theOriginal << ", \""
<< theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
SetErrorCode(OK);
}
@ -161,12 +159,12 @@ void GEOMImpl_IInsertOperations::Export
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
(const char* theFileName,
const char* theFormatName)
(const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatName)
{
SetErrorCode(KO);
if (!theFileName || !theFormatName) return NULL;
if (theFileName.IsEmpty() || theFormatName.IsEmpty()) return NULL;
//Add a new result object
Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
@ -180,12 +178,10 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
//Set parameters
GEOMImpl_IImportExport aCI (aFunction);
char* aFileName = (char*)theFileName;
aCI.SetFileName(aFileName);
aCI.SetFileName(theFileName);
char* aFormatName = (char*)theFormatName;
Handle(TCollection_HAsciiString) aHLibName;
if (!IsSupported(Standard_True, aFormatName, aHLibName)) {
if (!IsSupported(Standard_True, theFormatName, aHLibName)) {
return result;
}
TCollection_AsciiString aLibName = aHLibName->String();
@ -206,7 +202,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
//Make a Python command
GEOM::TPythonDump(aFunction) << result << " = geompy.Import(\""
<< theFileName << "\", \"" << theFormatName << "\")";
<< theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
SetErrorCode(OK);
return result;
@ -317,19 +313,20 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
//=============================================================================
Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
(const Standard_Boolean isImport,
const TCollection_AsciiString theFormat,
const TCollection_AsciiString& theFormat,
Handle(TCollection_HAsciiString)& theLibName)
{
if (!InitResMgr()) return Standard_False;
// Import/Export mode
Standard_CString aMode;
TCollection_AsciiString aMode;
//Standard_CString aMode;
if (isImport) aMode = "Import";
else aMode = "Export";
// Read supported formats for the certain mode
if (myResMgr->Find(aMode)) {
TCollection_AsciiString aFormats (myResMgr->Value(aMode));
if (myResMgr->Find(aMode.ToCString())) {
TCollection_AsciiString aFormats (myResMgr->Value(aMode.ToCString()));
if (aFormats.Search(theFormat) > -1) {
// Read library name for the supported format
TCollection_AsciiString aKey (theFormat);

View File

@ -19,11 +19,12 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
Standard_EXPORT Handle(GEOM_Object) MakeCopy (Handle(GEOM_Object) theOriginal);
Standard_EXPORT Handle(GEOM_Object) Import (const char* theFileName, const char* theFormatType);
Standard_EXPORT Handle(GEOM_Object) Import (const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatType);
Standard_EXPORT void Export (const Handle(GEOM_Object) theOriginal,
const char* theFileName,
const char* theFormatType);
const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatType);
Standard_EXPORT Standard_Boolean ImportTranslators (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
Handle(TColStd_HSequenceOfAsciiString)& thePatterns);
@ -32,7 +33,7 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
Handle(TColStd_HSequenceOfAsciiString)& thePatterns);
Standard_EXPORT Standard_Boolean IsSupported (const Standard_Boolean isImport,
const TCollection_AsciiString theFormat,
const TCollection_AsciiString& theFormat,
Handle(TCollection_HAsciiString)& theLibName);
private:

View File

@ -378,7 +378,7 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeShape
(list<Handle(GEOM_Object)> theShapes,
const Standard_Integer theObjectType,
const Standard_Integer theFunctionType,
const TCollection_AsciiString theMethodName)
const TCollection_AsciiString& theMethodName)
{
SetErrorCode(KO);

View File

@ -117,7 +117,7 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations {
Handle(GEOM_Object) MakeShape (list<Handle(GEOM_Object)> theShapes,
const Standard_Integer theObjectType,
const Standard_Integer theFunctionType,
const TCollection_AsciiString theMethodName);
const TCollection_AsciiString& theMethodName);
bool CheckTriangulation (const TopoDS_Shape& aShape);
};

View File

@ -285,8 +285,6 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation
GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
(const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane)
{
GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_nil();
//Set a not done flag
GetOperations()->SetNotDone();
@ -298,9 +296,8 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
// Make Sketcher
Handle(GEOM_Object) anObject =
GetOperations()->MakeSketcher(strdup(theCommand), aWorkingPlane);
GetOperations()->MakeSketcher((char*)theCommand, aWorkingPlane);
if (!GetOperations()->IsDone() || anObject.IsNull())
//return aGEOMObject._retn();
return GEOM::GEOM_Object::_nil();
return GetObject(anObject);
@ -315,8 +312,6 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
(const char* theCommand, GEOM::GEOM_Object_ptr theWorkingPlane)
{
GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_nil();
//Set a not done flag
GetOperations()->SetNotDone();
@ -325,9 +320,9 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
// Make Sketcher
Handle(GEOM_Object) anObject =
GetOperations()->MakeSketcherOnPlane(strdup(theCommand), aWorkingPlane);
GetOperations()->MakeSketcherOnPlane((char*)theCommand, aWorkingPlane);
if (!GetOperations()->IsDone() || anObject.IsNull())
return aGEOMObject._retn();
return GEOM::GEOM_Object::_nil();
return GetObject(anObject);
}

View File

@ -32,23 +32,23 @@
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Face.hxx>
#include <gp_Pln.hxx>
#include <gp_Ax2.hxx>
#include <BRepLib.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GeomAPI.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2d_Circle.hxx>
#include <Geom_Surface.hxx>
#include <Precision.hxx>
#include <GeomAPI.hxx>
#include <gp_Pln.hxx>
#include <gp_Ax2.hxx>
#include <TCollection_AsciiString.hxx>
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOMEDS)
#include <TColStd_Array1OfAsciiString.hxx>
#include "utilities.h"
@ -88,37 +88,37 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
myOK = Standard_False;
TCollection_AsciiString aCommand(CORBA::string_dup(aCmd));
//TCollection_AsciiString aCommand(CORBA::string_dup(aCmd));
TCollection_AsciiString aCommand ((char*)aCmd);
TCollection_AsciiString aToken = aCommand.Token(":", 1);
int n = 0;
// porting to WNT
TCollection_AsciiString* aTab = 0;
TColStd_Array1OfAsciiString aTab (0, aCommand.Length() - 1);
if ( aCommand.Length() )
{
aTab = new TCollection_AsciiString[ aCommand.Length() ];
while(aToken.Length() != 0) {
if(aCommand.Token(":", n + 1).Length() > 0)
aTab[n] = aCommand.Token(":", n + 1);
aTab(n) = aCommand.Token(":", n + 1);
aToken = aCommand.Token(":", ++n);
}
n = n - 1;
}
if ( aTab && aTab[0].Length() )
if ( aTab.Length() && aTab(0).Length() )
while(i < n) {
Standard_Real length = 0, radius = 0, angle = 0;
move = point;
int n1 = 0;
TCollection_AsciiString* a = new TCollection_AsciiString[ aTab[0].Length() ];
aToken = aTab[i].Token(" ", 1);
TColStd_Array1OfAsciiString a (0, aTab(0).Length());
aToken = aTab(i).Token(" ", 1);
while (aToken.Length() != 0) {
if(aTab[i].Token(" ", n1 + 1).Length() > 0)
a[n1] = aTab[i].Token(" ", n1 + 1);
aToken = aTab[i].Token(" ", ++n1);
if (aTab(i).Token(" ", n1 + 1).Length() > 0)
a(n1) = aTab(i).Token(" ", n1 + 1);
aToken = aTab(i).Token(" ", ++n1);
}
n1 = n1 - 1;
switch(a[0].Value(1))
switch(a(0).Value(1))
{
case 'F':
{
@ -127,23 +127,23 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
MESSAGE("profile : The F instruction must precede all moves");
return;
}
x0 = x = a[1].RealValue();
y0 = y = a[2].RealValue();
x0 = x = a(1).RealValue();
y0 = y = a(2).RealValue();
stayfirst = Standard_True;
break;
}
case 'O':
{
if (n1 != 4) goto badargs;
P.SetLocation(gp_Pnt(a[1].RealValue(), a[2].RealValue(), a[3].RealValue()));
P.SetLocation(gp_Pnt(a(1).RealValue(), a(2).RealValue(), a(3).RealValue()));
stayfirst = Standard_True;
break;
}
case 'P':
{
if (n1 != 7) goto badargs;
gp_Vec vn(a[1].RealValue(), a[2].RealValue(), a[3].RealValue());
gp_Vec vx(a[4].RealValue(), a[5].RealValue(), a[6].RealValue());
gp_Vec vn(a(1).RealValue(), a(2).RealValue(), a(3).RealValue());
gp_Vec vx(a(4).RealValue(), a(5).RealValue(), a(6).RealValue());
if (vn.Magnitude() <= Precision::Confusion() || vx.Magnitude() <= Precision::Confusion()) {
MESSAGE("profile : null direction");
return;
@ -156,8 +156,8 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
case 'X':
{
if (n1 != 2) goto badargs;
length = a[1].RealValue();
if (a[0] == "XX")
length = a(1).RealValue();
if (a(0) == "XX")
length -= x;
dx = 1; dy = 0;
move = line;
@ -166,8 +166,8 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
case 'Y':
{
if (n1 != 2) goto badargs;
length = a[1].RealValue();
if (a[0] == "YY")
length = a(1).RealValue();
if (a(0) == "YY")
length -= y;
dx = 0; dy = 1;
move = line;
@ -176,7 +176,7 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
case 'L':
{
if (n1 != 2) goto badargs;
length = a[1].RealValue();
length = a(1).RealValue();
if (Abs(length) > Precision::Confusion())
move = line;
else
@ -186,9 +186,9 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
case 'T':
{
if (n1 != 3) goto badargs;
Standard_Real vx = a[1].RealValue();
Standard_Real vy = a[2].RealValue();
if (a[0] == "TT") {
Standard_Real vx = a(1).RealValue();
Standard_Real vy = a(2).RealValue();
if (a(0) == "TT") {
vx -= x;
vy -= y;
}
@ -205,8 +205,8 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
case 'R':
{
if (n1 != 2) goto badargs;
angle = a[1].RealValue() * PI180;
if (a[0] == "RR") {
angle = a(1).RealValue() * PI180;
if (a(0) == "RR") {
dx = Cos(angle);
dy = Sin(angle);
}
@ -222,8 +222,8 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
case 'D':
{
if (n1 != 3) goto badargs;
Standard_Real vx = a[1].RealValue();
Standard_Real vy = a[2].RealValue();
Standard_Real vx = a(1).RealValue();
Standard_Real vy = a(2).RealValue();
length = Sqrt(vx * vx + vy * vy);
if (length > Precision::Confusion()) {
dx = vx / length;
@ -236,9 +236,9 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
case 'C':
{
if (n1 != 3) goto badargs;
radius = a[1].RealValue();
radius = a(1).RealValue();
if (Abs(radius) > Precision::Confusion()) {
angle = a[2].RealValue() * PI180;
angle = a(2).RealValue() * PI180;
move = circle;
}
else
@ -248,15 +248,15 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
case 'I':
{
if (n1 != 2) goto badargs;
length = a[1].RealValue();
if (a[0] == "IX") {
length = a(1).RealValue();
if (a(0) == "IX") {
if (Abs(dx) < Precision::Confusion()) {
MESSAGE("profile : cannot intersect, arg "<<i-1);
return;
}
length = (length - x) / dx;
}
else if (a[0] == "IY") {
else if (a(0) == "IY") {
if (Abs(dy) < Precision::Confusion()) {
MESSAGE("profile : cannot intersect, arg "<<i-1);
return;
@ -271,9 +271,9 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
}
case 'W':
{
if (a[0] == "WW")
if (a(0) == "WW")
close = Standard_True;
else if(a[0] == "WF") {
else if(a(0) == "WF") {
close = Standard_True;
face = Standard_True;
}
@ -282,7 +282,7 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd)
}
default:
{
MESSAGE("profile : unknown code "<<a[i]);
MESSAGE("profile : unknown code " << a(i));
return;
}
}
@ -371,10 +371,7 @@ again :
goto again;
}
}
delete a;
}
delete aTab;
aTab = 0;
// get the result, face or wire
if (move == none) {