From 1c8fc6bee2656bc89332e8a3ad61b855480c557e Mon Sep 17 00:00:00 2001 From: kgv Date: Tue, 12 Feb 2019 12:22:26 +0300 Subject: [PATCH] 0030493: Draw, ViewerTest - minor improvement of vdisplay command vdisplay no longer opens BREP file in case if Draw variable is not found. Draw::Get() unused Complain argument has been removed from method definition. Added Draw::GetExisting() and DBRep::GetExisting() commands never performing picking. --- src/DBRep/DBRep.cxx | 67 +++++------ src/DBRep/DBRep.hxx | 95 ++++++++-------- src/DDF/DDF.cxx | 2 +- src/DDF/DDF_BrowserCommands.cxx | 24 +++- src/DDataStd/DDataStd_DrawDisplayCommands.cxx | 22 ++-- src/DDataStd/DDataStd_TreeCommands.cxx | 8 +- src/DDocStd/DDocStd.cxx | 5 +- src/DDocStd/DDocStd_ApplicationCommands.cxx | 6 +- src/DDocStd/DDocStd_MTMCommands.cxx | 11 +- src/DNaming/DNaming_ToolsCommands.cxx | 2 +- src/Draw/Draw.hxx | 36 +++--- src/Draw/Draw_VariableCommands.cxx | 98 +++++++--------- src/QABugs/QABugs_1.cxx | 6 +- src/QABugs/QABugs_3.cxx | 1 - src/QADNaming/QADNaming_ToolsCommands.cxx | 2 +- src/ViewerTest/ViewerTest.cxx | 106 +++++------------- src/ViewerTest/ViewerTest_FilletCommands.cxx | 14 +-- src/XDEDRAW/XDEDRAW.cxx | 11 +- 18 files changed, 234 insertions(+), 282 deletions(-) diff --git a/src/DBRep/DBRep.cxx b/src/DBRep/DBRep.cxx index 27dd671ca2..faee1ff8e5 100644 --- a/src/DBRep/DBRep.cxx +++ b/src/DBRep/DBRep.cxx @@ -1291,42 +1291,43 @@ void DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S) Draw::Set(Name,D); } //======================================================================= -//function : Get -//purpose : +//function : getShape +//purpose : //======================================================================= -TopoDS_Shape DBRep::Get(Standard_CString& name, - const TopAbs_ShapeEnum typ, - const Standard_Boolean complain) +TopoDS_Shape DBRep::getShape (Standard_CString& theName, + TopAbs_ShapeEnum theType, + Standard_Boolean theToComplain) { - Standard_Boolean pick = name[0] == '.'; - TopoDS_Shape S; - Handle(DBRep_DrawableShape) D; - Handle(Draw_Drawable3D) DD = Draw::Get(name,complain); - if (!DD.IsNull()) - D = Handle(DBRep_DrawableShape)::DownCast(DD); - if (!D.IsNull()) { - S = D->Shape(); - if (typ != TopAbs_SHAPE) { - if (typ != S.ShapeType()) { - // try to find prom pick - if (pick) { - Standard_Real u,v; - DBRep_DrawableShape::LastPick(S,u,v); - } - } - if (typ != S.ShapeType()) { - if (complain) { - cout << name << " is not a "; - TopAbs::Print(typ,cout); - cout << " but a "; - TopAbs::Print(S.ShapeType(),cout); - cout << endl; - } - S = TopoDS_Shape(); - } - } + const Standard_Boolean toPick = theName[0] == '.'; + Handle(DBRep_DrawableShape) aDrawable = Handle(DBRep_DrawableShape)::DownCast (Draw::Get (theName)); + if (aDrawable.IsNull()) + { + return TopoDS_Shape(); } - return S; + + TopoDS_Shape aShape = aDrawable->Shape(); + if (theType != TopAbs_SHAPE + && theType != aShape.ShapeType() + && toPick) + { + // try to find prom pick + Standard_Real u, v; + DBRep_DrawableShape::LastPick (aShape, u, v); + } + if (theType != TopAbs_SHAPE + && theType != aShape.ShapeType()) + { + if (theToComplain) + { + std::cout << theName << " is not a "; + TopAbs::Print (theType, std::cout); + std::cout << " but a "; + TopAbs::Print (aShape.ShapeType(), std::cout); + std::cout << std::endl; + } + return TopoDS_Shape(); + } + return aShape; } static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv) diff --git a/src/DBRep/DBRep.hxx b/src/DBRep/DBRep.hxx index ef358034b8..57f8887794 100644 --- a/src/DBRep/DBRep.hxx +++ b/src/DBRep/DBRep.hxx @@ -17,23 +17,10 @@ #ifndef _DBRep_HeaderFile #define _DBRep_HeaderFile -#include -#include -#include - -#include -#include -#include #include -#include -#include -class TopoDS_Shape; -class DBRep_Edge; -class DBRep_Face; -class DBRep_HideData; -class DBRep_DrawableShape; -class DBRep_IsoBuilder; - +#include +#include +#include //! Used to display BRep objects using the DrawTrSurf //! package. @@ -54,12 +41,46 @@ public: //! variable if already set. Standard_EXPORT static void Set (const Standard_CString Name, const TopoDS_Shape& S); - //! Returns the shape in the variable . Returns - //! a null shape if the variable is not set or not of - //! the given . If is True a message - //! is printed on cout if the variable is not set. - Standard_EXPORT static TopoDS_Shape Get (Standard_CString& Name, const TopAbs_ShapeEnum Typ = TopAbs_SHAPE, const Standard_Boolean Complain = Standard_False); - + //! Returns the shape in the variable. + //! @param theName [in] [out] variable name, or "." to pick up shape interactively (the picked name will be returned then) + //! @param theType [in] shape type filter; function will return NULL if shape has different type + //! @param theToComplain [in] when TRUE, prints a message on cout if the variable is not set + static TopoDS_Shape Get (Standard_CString& theName, TopAbs_ShapeEnum theType = TopAbs_SHAPE, Standard_Boolean theToComplain = Standard_False) + { + return getShape (theName, theType, theToComplain); + } + + //! Returns the shape in the variable. + //! @param theName [in] [out] variable name, or "." to pick up shape interactively (the picked name will be returned then) + //! @param theType [in] shape type filter; function will return NULL if shape has different type + //! @param theToComplain [in] when TRUE, prints a message on cout if the variable is not set + static TopoDS_Shape Get (TCollection_AsciiString& theName, TopAbs_ShapeEnum theType = TopAbs_SHAPE, Standard_Boolean theToComplain = Standard_False) + { + Standard_CString aNamePtr = theName.ToCString(); + TopoDS_Shape aShape = getShape (aNamePtr, theType, theToComplain); + if (aNamePtr != theName.ToCString()) + { + theName = aNamePtr; + } + return aShape; + } + + //! Returns the shape in the variable. + //! @param theName [in] variable name + //! @param theType [in] shape type filter; function will return NULL if shape has different type + //! @param theToComplain [in] when TRUE, prints a message on cout if the variable is not set + static TopoDS_Shape GetExisting (const TCollection_AsciiString& theName, TopAbs_ShapeEnum theType = TopAbs_SHAPE, Standard_Boolean theToComplain = Standard_False) + { + if (theName.Length() == 1 + && theName.Value (1) == '.') + { + return TopoDS_Shape(); + } + + Standard_CString aNamePtr = theName.ToCString(); + return getShape (aNamePtr, theType, theToComplain); + } + //! Defines the basic commands. Standard_EXPORT static void BasicCommands (Draw_Interpretor& theCommands); @@ -86,32 +107,16 @@ public: //! get progress indicator Standard_EXPORT static Standard_Integer Discretisation(); - - - protected: - - - - -private: - - - - -friend class DBRep_Edge; -friend class DBRep_Face; -friend class DBRep_HideData; -friend class DBRep_DrawableShape; -friend class DBRep_IsoBuilder; + //! Returns the shape in the variable. + //! @param theName [in] [out] variable name, or "." to pick up shape interactively (the picked name will be returned then) + //! @param theType [in] shape type filter; function will return NULL if shape has different type + //! @param theToComplain [in] when TRUE, prints a message on cout if the variable is not set + Standard_EXPORT static TopoDS_Shape getShape (Standard_CString& theName, + TopAbs_ShapeEnum theType, + Standard_Boolean theToComplain); }; - - - - - - #endif // _DBRep_HeaderFile diff --git a/src/DDF/DDF.cxx b/src/DDF/DDF.cxx index dfdc73935c..d57b0c2182 100644 --- a/src/DDF/DDF.cxx +++ b/src/DDF/DDF.cxx @@ -75,7 +75,7 @@ Standard_Boolean DDF::GetDF (Standard_CString& Name, Handle(TDF_Data)& DF, const Standard_Boolean Complain) { - Handle(Standard_Transient) t = Draw::Get(Name, Complain); + Handle(Standard_Transient) t = Draw::Get (Name); Handle(DDF_Data) DDF = Handle(DDF_Data)::DownCast (t); //Handle(DDF_Data) DDF = Handle(DDF_Data)::DownCast (Draw::Get(Name, Complain)); if (!DDF.IsNull()) { diff --git a/src/DDF/DDF_BrowserCommands.cxx b/src/DDF/DDF_BrowserCommands.cxx index 0e4c5e24cb..e53ad940d0 100644 --- a/src/DDF/DDF_BrowserCommands.cxx +++ b/src/DDF/DDF_BrowserCommands.cxx @@ -103,8 +103,12 @@ static Standard_Integer DFOpenLabel (Draw_Interpretor& di, { if (n < 2) return 1; - Handle(DDF_Browser) browser = - Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True)); + Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1])); + if (browser.IsNull()) + { + std::cout << "Syntax error: browser '" << a[1] << "' not found\n"; + return 1; + } TDF_Label lab; if (n == 3) TDF_Tool::Label(browser->Data(),a[2],lab); @@ -128,8 +132,12 @@ static Standard_Integer DFOpenAttributeList(Draw_Interpretor& di, { if (n < 3) return 1; - Handle(DDF_Browser) browser = - Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True)); + Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1])); + if (browser.IsNull()) + { + std::cout << "Syntax error: browser '" << a[1] << "' not found\n"; + return 1; + } TDF_Label lab; TDF_Tool::Label(browser->Data(),a[2],lab); @@ -157,8 +165,12 @@ static Standard_Integer DFOpenAttribute (Draw_Interpretor& di, { if (n < 3) return 1; - Handle(DDF_Browser) browser = - Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True)); + Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1])); + if (browser.IsNull()) + { + std::cout << "Syntax error: browser '" << a[1] << "' not found\n"; + return 1; + } const Standard_Integer index = Draw::Atoi(a[2]); TCollection_AsciiString list = browser->OpenAttribute(index); diff --git a/src/DDataStd/DDataStd_DrawDisplayCommands.cxx b/src/DDataStd/DDataStd_DrawDisplayCommands.cxx index c0f718cbc6..40ef836630 100644 --- a/src/DDataStd/DDataStd_DrawDisplayCommands.cxx +++ b/src/DDataStd/DDataStd_DrawDisplayCommands.cxx @@ -86,18 +86,26 @@ static Standard_Integer DDataStd_PNT (Draw_Interpretor& di, //purpose : Rmdraw (name) //======================================================================= -static Standard_Integer DDataStd_Rmdraw (Draw_Interpretor& di, +static Standard_Integer DDataStd_Rmdraw (Draw_Interpretor& , Standard_Integer nb, const char** arg) { - if (nb == 2) { - Handle(Draw_Drawable3D) D3D; - D3D = Draw::Get(arg[1],Standard_True); - if (!D3D.IsNull()) dout.RemoveDrawable(D3D); + if (nb != 2) + { + std::cout << "Syntax error: wrong number of arguments\n"; + return 1; + } + + if (Handle(Draw_Drawable3D) D3D = Draw::Get (arg[1])) + { + dout.RemoveDrawable (D3D); return 0; } - di << "DDataStd_Rmdraw : Error : not done\n"; - return 1; + else + { + std::cout << "Syntax error: variable '" << arg[1] << "' not found\n"; + return 1; + } } //======================================================================= diff --git a/src/DDataStd/DDataStd_TreeCommands.cxx b/src/DDataStd/DDataStd_TreeCommands.cxx index 7a0a4be4b1..615ba5d9f1 100644 --- a/src/DDataStd/DDataStd_TreeCommands.cxx +++ b/src/DDataStd/DDataStd_TreeCommands.cxx @@ -347,8 +347,12 @@ static Standard_Integer DDataStd_OpenNode (Draw_Interpretor& di, { if (n < 2) return 1; - Handle(DDataStd_TreeBrowser) browser = - Handle(DDataStd_TreeBrowser)::DownCast (Draw::Get(a[1], Standard_True)); + Handle(DDataStd_TreeBrowser) browser = Handle(DDataStd_TreeBrowser)::DownCast (Draw::GetExisting (a[1])); + if (browser.IsNull()) + { + std::cout << "Syntax error: browser '" << a[1] << "' not found\n"; + return 1; + } TDF_Label lab; if (n == 3) TDF_Tool::Label(browser->Label().Data(),a[2],lab); diff --git a/src/DDocStd/DDocStd.cxx b/src/DDocStd/DDocStd.cxx index 7153c74211..a7887910b8 100644 --- a/src/DDocStd/DDocStd.cxx +++ b/src/DDocStd/DDocStd.cxx @@ -71,10 +71,7 @@ Standard_Boolean DDocStd::GetDocument (Standard_CString& Name, Handle(TDocStd_Document)& DOC, const Standard_Boolean Complain) { - - Handle(Draw_Drawable3D) D = Draw::Get(Name,Standard_False); - - Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (D); + Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (Draw::GetExisting (Name)); if (DD.IsNull()) { if (Complain) cout << Name << " is not a Document" << endl; return Standard_False; diff --git a/src/DDocStd/DDocStd_ApplicationCommands.cxx b/src/DDocStd/DDocStd_ApplicationCommands.cxx index 33ba7adf18..c7842ffcc4 100644 --- a/src/DDocStd/DDocStd_ApplicationCommands.cxx +++ b/src/DDocStd/DDocStd_ApplicationCommands.cxx @@ -348,8 +348,10 @@ static Standard_Integer DDocStd_Close (Draw_Interpretor& /*theDI*/, aDocApp->Close (aDoc); - Handle(Draw_Drawable3D) aDrawable = Draw::Get (aDocName, Standard_False); - dout.RemoveDrawable (aDrawable); + if (Handle(Draw_Drawable3D) aDrawable = Draw::GetExisting (aDocName)) + { + dout.RemoveDrawable (aDrawable); + } Draw::Set (theArgVec[1], Handle(Draw_Drawable3D)()); return 0; } diff --git a/src/DDocStd/DDocStd_MTMCommands.cxx b/src/DDocStd/DDocStd_MTMCommands.cxx index 0cddf6c9d3..47afb7e155 100644 --- a/src/DDocStd/DDocStd_MTMCommands.cxx +++ b/src/DDocStd/DDocStd_MTMCommands.cxx @@ -206,20 +206,19 @@ static int mtmNestedMode (Draw_Interpretor& di, int n, const char** a) static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { - if ( argc <4 ) { di << "ERROR: Too few args\n"; return 0; } - Handle(DDF_Browser) browser = - Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True)); - if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; } + if ( argc < 4 ) { di << "ERROR: Too few args\n"; return 1; } + Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1])); + if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; } TDF_Label lab; TDF_Tool::Label(browser->Data(),argv[2],lab); - if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; } + if ( lab.IsNull() ) { di << "Syntax error: label is Null: " << argv[2] << "\n"; return 1; } Standard_Integer num = Draw::Atoi ( argv[3] ); TDF_AttributeIterator itr(lab,Standard_False); for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next(); - if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found\n"; return 0; } + if ( ! itr.More() ) { di << "Syntax error: Attribute #" << num << " not found\n"; return 1; } const Handle(TDF_Attribute)& att = itr.Value(); if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) diff --git a/src/DNaming/DNaming_ToolsCommands.cxx b/src/DNaming/DNaming_ToolsCommands.cxx index 3a7a665b21..2154ea7412 100644 --- a/src/DNaming/DNaming_ToolsCommands.cxx +++ b/src/DNaming/DNaming_ToolsCommands.cxx @@ -132,7 +132,7 @@ static Standard_Integer DNaming_TCopyShape (Draw_Interpretor& di, DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName); for(;itrn.More();itrn.Next()) { TCollection_AsciiString name = itrn.Value(); - const TopoDS_Shape& Result = TR.Copied(itrn.Key()); + const TopoDS_Shape Result = TR.Copied(itrn.Key()); DBRep::Set(name.ToCString(), Result); di.AppendElement(name.ToCString()); } diff --git a/src/Draw/Draw.hxx b/src/Draw/Draw.hxx index e546d98902..929cd2958d 100644 --- a/src/Draw/Draw.hxx +++ b/src/Draw/Draw.hxx @@ -73,16 +73,18 @@ public: //! Returns main DRAW interpretor. Standard_EXPORT static Draw_Interpretor& GetInterpretor(); - - //! Returns a variable value. Null if the variable - //! does not exist, a warning is printed if Complain - //! is True. - //! - //! The name "." does a graphic selection. If the - //! selection is a variable is overwritten with - //! the name of the variable. - Standard_EXPORT static Handle(Draw_Drawable3D) Get (Standard_CString& Name, const Standard_Boolean Complain = Standard_True); - + + //! Returns a variable value. + //! The name "." does a graphic selection; in this case theName will be is overwritten with the name of the variable. + static Handle(Draw_Drawable3D) Get (Standard_CString& theName) { return getDrawable (theName, Standard_True); } + + //! Returns a variable value. + static Handle(Draw_Drawable3D) GetExisting (const Standard_CString& theName) + { + Standard_CString aName = theName; + return getDrawable (aName, Standard_False); + } + //! Gets a numeric variable. Returns True if the //! variable exist. Standard_EXPORT static Standard_Boolean Get (const Standard_CString Name, Standard_Real& val); @@ -129,20 +131,16 @@ public: //! Defines Draw unit commands Standard_EXPORT static void UnitCommands (Draw_Interpretor& I); - - - protected: - - - + //! Returns a variable value. + //! @param theName [in] [out] variable name, or "." to activate picking + //! @param theToAllowPick [in] when TRUE, "." name will activate picking + Standard_EXPORT static Handle(Draw_Drawable3D) getDrawable (Standard_CString& theName, + Standard_Boolean theToAllowPick); private: - - - friend class Draw_Drawable3D; friend class Draw_Drawable2D; friend class Draw_Color; diff --git a/src/Draw/Draw_VariableCommands.cxx b/src/Draw/Draw_VariableCommands.cxx index d60318c8bf..a4d34bec48 100644 --- a/src/Draw/Draw_VariableCommands.cxx +++ b/src/Draw/Draw_VariableCommands.cxx @@ -627,7 +627,7 @@ static Standard_Integer dgetenv(Draw_Interpretor& di, Standard_Integer argc, con static Standard_Integer isdraw(Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n != 2) return 1; - Handle(Draw_Drawable3D) D = Draw::Get(a[1],Standard_False); + Handle(Draw_Drawable3D) D = Draw::Get (a[1]); if (D.IsNull()) di << "0"; else @@ -643,7 +643,7 @@ static Standard_Integer isdraw(Draw_Interpretor& di, Standard_Integer n, const c Standard_Integer isprot(Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n != 2) return 1; - Handle(Draw_Drawable3D) D = Draw::Get(a[1],Standard_False); + Handle(Draw_Drawable3D) D = Draw::Get(a[1]); if (D.IsNull()) di << "0"; else { @@ -814,75 +814,63 @@ void Draw::Set(const Standard_CString name, //function : Set //purpose : //======================================================================= -void Draw::Set(const Standard_CString Name, const Standard_Real val) +void Draw::Set(const Standard_CString theName, const Standard_Real theValue) { - if ((Name[0] == '.') && (Name[1] == '\0')) return; - Standard_CString aName = Name; - Handle(Draw_Drawable3D) D = Draw::Get(aName,Standard_False); - Handle(Draw_Number) N; - if (!D.IsNull()) { - N = Handle(Draw_Number)::DownCast(D); - } - if (N.IsNull()) { - N = new Draw_Number(val); - Draw::Set(aName,N,Standard_False); + if (Handle(Draw_Number) aNumber = Handle(Draw_Number)::DownCast (Draw::GetExisting (theName))) + { + aNumber->Value (theValue); } else - N->Value(val); + { + aNumber = new Draw_Number (theValue); + Draw::Set (theName, aNumber, Standard_False); + } } + //======================================================================= -//function : Get -//purpose : +//function : getDrawable +//purpose : //======================================================================= -Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name, - const Standard_Boolean ) +Handle(Draw_Drawable3D) Draw::getDrawable (Standard_CString& theName, + Standard_Boolean theToAllowPick) { - Standard_Boolean pick = ((name[0] == '.') && (name[1] == '\0')); - Handle(Draw_Drawable3D) D; - if (pick) { - cout << "Pick an object" << endl; - dout.Select(p_id,p_X,p_Y,p_b); - dout.Pick(p_id,p_X,p_Y,5,D,0); - if (!D.IsNull()) { - if (D->Name()) { - name = p_Name = D->Name(); - //p_Name = (char *)D->Name(); - } - } + const Standard_Boolean toPick = ((theName[0] == '.') && (theName[1] == '\0')); + if (!toPick) + { + ClientData aCD = Tcl_VarTraceInfo (Draw::GetInterpretor().Interp(), theName, TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar, NULL); + Handle(Draw_Drawable3D) aDrawable = reinterpret_cast(aCD); + return theVariables.Contains (aDrawable) + ? aDrawable + : Handle(Draw_Drawable3D)(); } - else { - ClientData aCD = - Tcl_VarTraceInfo(Draw::GetInterpretor().Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, - tracevar, NULL); - D = reinterpret_cast(aCD); - if (!theVariables.Contains(D)) - D.Nullify(); -#if 0 - if (D.IsNull() && complain) - cout <Name() != NULL) + { + theName = p_Name = aDrawable->Name(); + } + return aDrawable; } //======================================================================= //function : Get //purpose : //======================================================================= -Standard_Boolean Draw::Get(const Standard_CString name, - Standard_Real& val) +Standard_Boolean Draw::Get (const Standard_CString theName, + Standard_Real& theValue) { - if ((name[0] == '.') && (name[1] == '\0')) { - return Standard_False; - } - Standard_CString aName = name; - Handle(Draw_Drawable3D) D = Draw::Get(aName,Standard_False); - if (!D.IsNull()) { - Handle(Draw_Number) N = Handle(Draw_Number)::DownCast(D); - if (!N.IsNull()) { - val = N->Value(); - return Standard_True; - } + if (Handle(Draw_Number) aNumber = Handle(Draw_Number)::DownCast (Draw::GetExisting (theName))) + { + theValue = aNumber->Value(); + return Standard_True; } return Standard_False; } diff --git a/src/QABugs/QABugs_1.cxx b/src/QABugs/QABugs_1.cxx index b713c743cc..d0a6dd0934 100644 --- a/src/QABugs/QABugs_1.cxx +++ b/src/QABugs/QABugs_1.cxx @@ -92,8 +92,10 @@ static Standard_Integer OCC159bug (Draw_Interpretor& di, Standard_Integer argc, Handle(TDocStd_Application) A = DDocStd::GetApplication(); A->Close(D); - Handle(Draw_Drawable3D) DD = Draw::Get(argv[1],Standard_False); - dout.RemoveDrawable (DD); + if (Handle(Draw_Drawable3D) DD = Draw::GetExisting (argv[1])) + { + dout.RemoveDrawable (DD); + } Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument(); if (OwnerD2.IsNull()) { diff --git a/src/QABugs/QABugs_3.cxx b/src/QABugs/QABugs_3.cxx index 4185161e34..e62df60526 100644 --- a/src/QABugs/QABugs_3.cxx +++ b/src/QABugs/QABugs_3.cxx @@ -596,7 +596,6 @@ static Standard_Integer BUC60876_ (Draw_Interpretor& di, } TopoDS_Shape aShape = DBRep::Get(argv[1]); Handle(AIS_InteractiveObject) anIO = new AIS_Shape(aShape); -// Handle(AIS_InteractiveObject) anIOa = ViewerTest::GetAISShapeFromName(argv[1]); anIO->SetHilightMode((argc == 3) ? Draw::Atoi(argv[2]) : 1); aContext->Display (anIO, Standard_True); return 0; diff --git a/src/QADNaming/QADNaming_ToolsCommands.cxx b/src/QADNaming/QADNaming_ToolsCommands.cxx index 201a36d2ed..aabc6f6f85 100644 --- a/src/QADNaming/QADNaming_ToolsCommands.cxx +++ b/src/QADNaming/QADNaming_ToolsCommands.cxx @@ -137,7 +137,7 @@ static Standard_Integer QADNaming_TCopyShape (Draw_Interpretor& di, DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName); for(;itrn.More();itrn.Next()) { TCollection_AsciiString name = itrn.Value(); - const TopoDS_Shape& Result = TR.Copied(itrn.Key()); + const TopoDS_Shape Result = TR.Copied(itrn.Key()); DBRep::Set(name.ToCString(), Result); di.AppendElement(name.ToCString()); } diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 8fe1b643e9..b9f592bad5 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -652,51 +652,6 @@ static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx, return Standard_True; } -//============================================================================== -//function : GetShapeFromName -//purpose : Compute an Shape from a draw variable or a file name -//============================================================================== - -static TopoDS_Shape GetShapeFromName(const char* name) -{ - TopoDS_Shape S = DBRep::Get(name); - - if ( S.IsNull() ) { - BRep_Builder aBuilder; - BRepTools::Read( S, name, aBuilder); - } - - return S; -} - -//============================================================================== -//function : GetAISShapeFromName -//purpose : Compute an AIS_Shape from a draw variable or a file name -//============================================================================== -Handle(AIS_Shape) GetAISShapeFromName(const char* name) -{ - Handle(AIS_InteractiveObject) aPrs; - if (GetMapOfAIS().Find2 (name, aPrs) - && !aPrs.IsNull()) - { - if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs)) - { - return aShapePrs; - } - - std::cout << "an Object which is not an AIS_Shape already has this name!!!\n"; - return Handle(AIS_Shape)(); - } - - TopoDS_Shape aShape = GetShapeFromName (name); - if (!aShape.IsNull()) - { - return new AIS_Shape(aShape); - } - return Handle(AIS_Shape)(); -} - - //============================================================================== //function : Clear //purpose : Remove all the object from the viewer @@ -4458,14 +4413,15 @@ static int VDisplay2 (Draw_Interpretor& theDI, // Display interactive objects for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter) { - const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter); + const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter); Handle(AIS_InteractiveObject) aShape; if (!GetMapOfAIS().Find2 (aName, aShape)) { // create the AIS_Shape from a name - aShape = GetAISShapeFromName (aName.ToCString()); - if (!aShape.IsNull()) + TopoDS_Shape aDrawShape = DBRep::GetExisting (aName); + if (!aDrawShape.IsNull()) { + aShape = new AIS_Shape (aDrawShape); if (isMutable != -1) { aShape->SetMutable (isMutable == 1); @@ -4553,10 +4509,10 @@ static int VDisplay2 (Draw_Interpretor& theDI, } else { - theDI << "Display " << aName.ToCString() << "\n"; + theDI << "Display " << aName << "\n"; // update the Shape in the AIS_Shape - TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString()); + TopoDS_Shape aNewShape = DBRep::GetExisting (aName); Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape); if (!aShapePrs.IsNull()) { @@ -4688,7 +4644,13 @@ static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv) TCollection_AsciiString name=argv[1]; GetMapOfAIS().Find2(name, TheAisIO); if (TheAisIO.IsNull()) - TheAisIO=GetAISShapeFromName(name.ToCString()); + { + TopoDS_Shape aDrawShape = DBRep::GetExisting (name); + if (!aDrawShape.IsNull()) + { + TheAisIO = new AIS_Shape (aDrawShape); + } + } if (HaveToSet) TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True); @@ -5791,42 +5753,28 @@ static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/, } // Parse input arguments - TColStd_SequenceOfAsciiString aNamesOfIO; for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) { const TCollection_AsciiString aName = theArgVec[anArgIter]; - aNamesOfIO.Append (aName); - } - - if (aNamesOfIO.IsEmpty()) - { - std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n"; - return 1; - } - - // Load selection of interactive objects - for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter) - { - const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter); - Handle(AIS_InteractiveObject) aShape; if (!GetMapOfAIS().Find2 (aName, aShape)) { - aShape = GetAISShapeFromName (aName.ToCString()); - } - - if (!aShape.IsNull()) - { - if (!GetMapOfAIS().IsBound2 (aName)) + TopoDS_Shape aDrawShape = DBRep::GetExisting (aName); + if (!aDrawShape.IsNull()) { + aShape = new AIS_Shape (aDrawShape); GetMapOfAIS().Bind (aShape, aName); } - - aCtx->Load (aShape, -1); - aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True); } - } + if (aShape.IsNull()) + { + std::cout << "Syntax error: presentation '" << aName << "' not found\n"; + return 1; + } + aCtx->Load (aShape, -1); + aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True); + } return 0; } @@ -6271,10 +6219,10 @@ static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, cons Standard_Real anAngle = 0; Standard_Boolean Rev = Standard_False; Standard_Integer rev = 0; - TopoDS_Shape Solid = GetShapeFromName(argv[1]); - TopoDS_Shape face = GetShapeFromName(argv[2]); + TopoDS_Shape Solid = DBRep::Get (argv[1]); + TopoDS_Shape face = DBRep::Get (argv[2]); TopoDS_Face Face = TopoDS::Face(face); - TopoDS_Shape Plane = GetShapeFromName(argv[3]); + TopoDS_Shape Plane = DBRep::Get (argv[3]); if (Plane.IsNull ()) { di << "TEST : Plane is NULL\n"; return 1; diff --git a/src/ViewerTest/ViewerTest_FilletCommands.cxx b/src/ViewerTest/ViewerTest_FilletCommands.cxx index cfeb904b7f..5a0b66da8a 100644 --- a/src/ViewerTest/ViewerTest_FilletCommands.cxx +++ b/src/ViewerTest/ViewerTest_FilletCommands.cxx @@ -51,9 +51,6 @@ # include #endif -extern Handle(AIS_Shape) GetAISShapeFromName(const char* name); - - static Standard_Real t3d = 1.e-4; static Standard_Real t2d = 1.e-5; static Standard_Real ta = 1.e-2; @@ -124,16 +121,9 @@ static Standard_Integer VBLEND(Draw_Interpretor& di, Standard_Integer narg, cons TopoDS_Shape res = Rakk->Shape(); DBRep::Set(a[1],res); - // visu resultat... - Handle(AIS_Shape) AS = GetAISShapeFromName(a[1]); - Handle(AIS_Shape) Start = GetAISShapeFromName(a[2]); - Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); - Ctx->Erase(Start,Standard_False); - if(Ctx->IsDisplayed(AS)) - Ctx->Redisplay (AS, Standard_True); - else - Ctx->Display (AS, Standard_True); + ViewerTest::Display (a[2], Handle(AIS_InteractiveObject)(), false); + ViewerTest::Display (a[1], new AIS_Shape (res), true); return 0; } diff --git a/src/XDEDRAW/XDEDRAW.cxx b/src/XDEDRAW/XDEDRAW.cxx index 606a6118c8..5f5b83af37 100644 --- a/src/XDEDRAW/XDEDRAW.cxx +++ b/src/XDEDRAW/XDEDRAW.cxx @@ -621,20 +621,19 @@ static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const //======================================================================= static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { - if ( argc <4 ) { di << "ERROR: Too few args\n"; return 0; } - Handle(DDF_Browser) browser = - Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True)); - if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; } + if ( argc < 4 ) { std::cout << "Syntax error: Too few args\n"; return 1; } + Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1])); + if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; } TDF_Label lab; TDF_Tool::Label(browser->Data(),argv[2],lab); - if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; } + if ( lab.IsNull() ) { std::cout << "Syntax error: label is Null: " << argv[2] << "\n"; return 1; } Standard_Integer num = Draw::Atoi ( argv[3] ); TDF_AttributeIterator itr(lab,Standard_False); for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next(); - if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found\n"; return 0; } + if ( ! itr.More() ) { std::cout << "Syntax error: Attribute #" << num << " not found\n"; return 1; } const Handle(TDF_Attribute)& att = itr.Value(); if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {