1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

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.
This commit is contained in:
kgv 2019-02-12 12:22:26 +03:00 committed by apn
parent d95f5ce102
commit 1c8fc6bee2
18 changed files with 234 additions and 282 deletions

View File

@ -1291,42 +1291,43 @@ void DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S)
Draw::Set(Name,D); Draw::Set(Name,D);
} }
//======================================================================= //=======================================================================
//function : Get //function : getShape
//purpose : //purpose :
//======================================================================= //=======================================================================
TopoDS_Shape DBRep::Get(Standard_CString& name, TopoDS_Shape DBRep::getShape (Standard_CString& theName,
const TopAbs_ShapeEnum typ, TopAbs_ShapeEnum theType,
const Standard_Boolean complain) Standard_Boolean theToComplain)
{ {
Standard_Boolean pick = name[0] == '.'; const Standard_Boolean toPick = theName[0] == '.';
TopoDS_Shape S; Handle(DBRep_DrawableShape) aDrawable = Handle(DBRep_DrawableShape)::DownCast (Draw::Get (theName));
Handle(DBRep_DrawableShape) D; if (aDrawable.IsNull())
Handle(Draw_Drawable3D) DD = Draw::Get(name,complain); {
if (!DD.IsNull()) return TopoDS_Shape();
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();
}
}
} }
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) static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)

View File

@ -17,23 +17,10 @@
#ifndef _DBRep_HeaderFile #ifndef _DBRep_HeaderFile
#define _DBRep_HeaderFile #define _DBRep_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_CString.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <Standard_Boolean.hxx>
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
#include <Standard_Real.hxx> #include <TCollection_AsciiString.hxx>
#include <Standard_Integer.hxx> #include <TopAbs_ShapeEnum.hxx>
class TopoDS_Shape; #include <TopoDS_Shape.hxx>
class DBRep_Edge;
class DBRep_Face;
class DBRep_HideData;
class DBRep_DrawableShape;
class DBRep_IsoBuilder;
//! Used to display BRep objects using the DrawTrSurf //! Used to display BRep objects using the DrawTrSurf
//! package. //! package.
@ -54,12 +41,46 @@ public:
//! variable if already set. //! variable if already set.
Standard_EXPORT static void Set (const Standard_CString Name, const TopoDS_Shape& S); Standard_EXPORT static void Set (const Standard_CString Name, const TopoDS_Shape& S);
//! Returns the shape in the variable <Name>. Returns //! Returns the shape in the variable.
//! a null shape if the variable is not set or not of //! @param theName [in] [out] variable name, or "." to pick up shape interactively (the picked name will be returned then)
//! the given <Typ>. If <Complain> is True a message //! @param theType [in] shape type filter; function will return NULL if shape has different type
//! is printed on cout if the variable is not set. //! @param theToComplain [in] when TRUE, prints a message 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); 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. //! Defines the basic commands.
Standard_EXPORT static void BasicCommands (Draw_Interpretor& theCommands); Standard_EXPORT static void BasicCommands (Draw_Interpretor& theCommands);
@ -86,32 +107,16 @@ public:
//! get progress indicator //! get progress indicator
Standard_EXPORT static Standard_Integer Discretisation(); Standard_EXPORT static Standard_Integer Discretisation();
protected: protected:
//! 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
private: Standard_EXPORT static TopoDS_Shape getShape (Standard_CString& theName,
TopAbs_ShapeEnum theType,
Standard_Boolean theToComplain);
friend class DBRep_Edge;
friend class DBRep_Face;
friend class DBRep_HideData;
friend class DBRep_DrawableShape;
friend class DBRep_IsoBuilder;
}; };
#endif // _DBRep_HeaderFile #endif // _DBRep_HeaderFile

View File

@ -75,7 +75,7 @@ Standard_Boolean DDF::GetDF (Standard_CString& Name,
Handle(TDF_Data)& DF, Handle(TDF_Data)& DF,
const Standard_Boolean Complain) 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 (t);
//Handle(DDF_Data) DDF = Handle(DDF_Data)::DownCast (Draw::Get(Name, Complain)); //Handle(DDF_Data) DDF = Handle(DDF_Data)::DownCast (Draw::Get(Name, Complain));
if (!DDF.IsNull()) { if (!DDF.IsNull()) {

View File

@ -103,8 +103,12 @@ static Standard_Integer DFOpenLabel (Draw_Interpretor& di,
{ {
if (n < 2) return 1; if (n < 2) return 1;
Handle(DDF_Browser) browser = Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1]));
Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True)); if (browser.IsNull())
{
std::cout << "Syntax error: browser '" << a[1] << "' not found\n";
return 1;
}
TDF_Label lab; TDF_Label lab;
if (n == 3) TDF_Tool::Label(browser->Data(),a[2],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; if (n < 3) return 1;
Handle(DDF_Browser) browser = Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1]));
Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True)); if (browser.IsNull())
{
std::cout << "Syntax error: browser '" << a[1] << "' not found\n";
return 1;
}
TDF_Label lab; TDF_Label lab;
TDF_Tool::Label(browser->Data(),a[2],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; if (n < 3) return 1;
Handle(DDF_Browser) browser = Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1]));
Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True)); if (browser.IsNull())
{
std::cout << "Syntax error: browser '" << a[1] << "' not found\n";
return 1;
}
const Standard_Integer index = Draw::Atoi(a[2]); const Standard_Integer index = Draw::Atoi(a[2]);
TCollection_AsciiString list = browser->OpenAttribute(index); TCollection_AsciiString list = browser->OpenAttribute(index);

View File

@ -86,18 +86,26 @@ static Standard_Integer DDataStd_PNT (Draw_Interpretor& di,
//purpose : Rmdraw (name) //purpose : Rmdraw (name)
//======================================================================= //=======================================================================
static Standard_Integer DDataStd_Rmdraw (Draw_Interpretor& di, static Standard_Integer DDataStd_Rmdraw (Draw_Interpretor& ,
Standard_Integer nb, Standard_Integer nb,
const char** arg) const char** arg)
{ {
if (nb == 2) { if (nb != 2)
Handle(Draw_Drawable3D) D3D; {
D3D = Draw::Get(arg[1],Standard_True); std::cout << "Syntax error: wrong number of arguments\n";
if (!D3D.IsNull()) dout.RemoveDrawable(D3D); return 1;
}
if (Handle(Draw_Drawable3D) D3D = Draw::Get (arg[1]))
{
dout.RemoveDrawable (D3D);
return 0; return 0;
} }
di << "DDataStd_Rmdraw : Error : not done\n"; else
return 1; {
std::cout << "Syntax error: variable '" << arg[1] << "' not found\n";
return 1;
}
} }
//======================================================================= //=======================================================================

View File

@ -347,8 +347,12 @@ static Standard_Integer DDataStd_OpenNode (Draw_Interpretor& di,
{ {
if (n < 2) return 1; if (n < 2) return 1;
Handle(DDataStd_TreeBrowser) browser = Handle(DDataStd_TreeBrowser) browser = Handle(DDataStd_TreeBrowser)::DownCast (Draw::GetExisting (a[1]));
Handle(DDataStd_TreeBrowser)::DownCast (Draw::Get(a[1], Standard_True)); if (browser.IsNull())
{
std::cout << "Syntax error: browser '" << a[1] << "' not found\n";
return 1;
}
TDF_Label lab; TDF_Label lab;
if (n == 3) TDF_Tool::Label(browser->Label().Data(),a[2],lab); if (n == 3) TDF_Tool::Label(browser->Label().Data(),a[2],lab);

View File

@ -71,10 +71,7 @@ Standard_Boolean DDocStd::GetDocument (Standard_CString& Name,
Handle(TDocStd_Document)& DOC, Handle(TDocStd_Document)& DOC,
const Standard_Boolean Complain) const Standard_Boolean Complain)
{ {
Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (Draw::GetExisting (Name));
Handle(Draw_Drawable3D) D = Draw::Get(Name,Standard_False);
Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (D);
if (DD.IsNull()) { if (DD.IsNull()) {
if (Complain) cout << Name << " is not a Document" << endl; if (Complain) cout << Name << " is not a Document" << endl;
return Standard_False; return Standard_False;

View File

@ -348,8 +348,10 @@ static Standard_Integer DDocStd_Close (Draw_Interpretor& /*theDI*/,
aDocApp->Close (aDoc); aDocApp->Close (aDoc);
Handle(Draw_Drawable3D) aDrawable = Draw::Get (aDocName, Standard_False); if (Handle(Draw_Drawable3D) aDrawable = Draw::GetExisting (aDocName))
dout.RemoveDrawable (aDrawable); {
dout.RemoveDrawable (aDrawable);
}
Draw::Set (theArgVec[1], Handle(Draw_Drawable3D)()); Draw::Set (theArgVec[1], Handle(Draw_Drawable3D)());
return 0; return 0;
} }

View File

@ -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) static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{ {
if ( argc <4 ) { di << "ERROR: Too few args\n"; return 0; } if ( argc < 4 ) { di << "ERROR: Too few args\n"; return 1; }
Handle(DDF_Browser) browser = Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1]));
Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True)); if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; }
if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
TDF_Label lab; TDF_Label lab;
TDF_Tool::Label(browser->Data(),argv[2],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] ); Standard_Integer num = Draw::Atoi ( argv[3] );
TDF_AttributeIterator itr(lab,Standard_False); TDF_AttributeIterator itr(lab,Standard_False);
for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next(); 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(); const Handle(TDF_Attribute)& att = itr.Value();
if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) )

View File

@ -132,7 +132,7 @@ static Standard_Integer DNaming_TCopyShape (Draw_Interpretor& di,
DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName); DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName);
for(;itrn.More();itrn.Next()) { for(;itrn.More();itrn.Next()) {
TCollection_AsciiString name = itrn.Value(); 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); DBRep::Set(name.ToCString(), Result);
di.AppendElement(name.ToCString()); di.AppendElement(name.ToCString());
} }

View File

@ -73,16 +73,18 @@ public:
//! Returns main DRAW interpretor. //! Returns main DRAW interpretor.
Standard_EXPORT static Draw_Interpretor& GetInterpretor(); Standard_EXPORT static Draw_Interpretor& GetInterpretor();
//! Returns a variable value. Null if the variable //! Returns a variable value.
//! does not exist, a warning is printed if Complain //! The name "." does a graphic selection; in this case theName will be is overwritten with the name of the variable.
//! is True. static Handle(Draw_Drawable3D) Get (Standard_CString& theName) { return getDrawable (theName, Standard_True); }
//!
//! The name "." does a graphic selection. If the //! Returns a variable value.
//! selection is a variable <Name> is overwritten with static Handle(Draw_Drawable3D) GetExisting (const Standard_CString& theName)
//! the name of the variable. {
Standard_EXPORT static Handle(Draw_Drawable3D) Get (Standard_CString& Name, const Standard_Boolean Complain = Standard_True); Standard_CString aName = theName;
return getDrawable (aName, Standard_False);
}
//! Gets a numeric variable. Returns True if the //! Gets a numeric variable. Returns True if the
//! variable exist. //! variable exist.
Standard_EXPORT static Standard_Boolean Get (const Standard_CString Name, Standard_Real& val); Standard_EXPORT static Standard_Boolean Get (const Standard_CString Name, Standard_Real& val);
@ -129,20 +131,16 @@ public:
//! Defines Draw unit commands //! Defines Draw unit commands
Standard_EXPORT static void UnitCommands (Draw_Interpretor& I); Standard_EXPORT static void UnitCommands (Draw_Interpretor& I);
protected: 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: private:
friend class Draw_Drawable3D; friend class Draw_Drawable3D;
friend class Draw_Drawable2D; friend class Draw_Drawable2D;
friend class Draw_Color; friend class Draw_Color;

View File

@ -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) static Standard_Integer isdraw(Draw_Interpretor& di, Standard_Integer n, const char** a)
{ {
if (n != 2) return 1; 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()) if (D.IsNull())
di << "0"; di << "0";
else 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) Standard_Integer isprot(Draw_Interpretor& di, Standard_Integer n, const char** a)
{ {
if (n != 2) return 1; 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()) if (D.IsNull())
di << "0"; di << "0";
else { else {
@ -814,75 +814,63 @@ void Draw::Set(const Standard_CString name,
//function : Set //function : Set
//purpose : //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; if (Handle(Draw_Number) aNumber = Handle(Draw_Number)::DownCast (Draw::GetExisting (theName)))
Standard_CString aName = Name; {
Handle(Draw_Drawable3D) D = Draw::Get(aName,Standard_False); aNumber->Value (theValue);
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);
} }
else else
N->Value(val); {
aNumber = new Draw_Number (theValue);
Draw::Set (theName, aNumber, Standard_False);
}
} }
//======================================================================= //=======================================================================
//function : Get //function : getDrawable
//purpose : //purpose :
//======================================================================= //=======================================================================
Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name, Handle(Draw_Drawable3D) Draw::getDrawable (Standard_CString& theName,
const Standard_Boolean ) Standard_Boolean theToAllowPick)
{ {
Standard_Boolean pick = ((name[0] == '.') && (name[1] == '\0')); const Standard_Boolean toPick = ((theName[0] == '.') && (theName[1] == '\0'));
Handle(Draw_Drawable3D) D; if (!toPick)
if (pick) { {
cout << "Pick an object" << endl; ClientData aCD = Tcl_VarTraceInfo (Draw::GetInterpretor().Interp(), theName, TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar, NULL);
dout.Select(p_id,p_X,p_Y,p_b); Handle(Draw_Drawable3D) aDrawable = reinterpret_cast<Draw_Drawable3D*>(aCD);
dout.Pick(p_id,p_X,p_Y,5,D,0); return theVariables.Contains (aDrawable)
if (!D.IsNull()) { ? aDrawable
if (D->Name()) { : Handle(Draw_Drawable3D)();
name = p_Name = D->Name();
//p_Name = (char *)D->Name();
}
}
} }
else { else if (!theToAllowPick)
ClientData aCD = {
Tcl_VarTraceInfo(Draw::GetInterpretor().Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, return Handle(Draw_Drawable3D)();
tracevar, NULL);
D = reinterpret_cast<Draw_Drawable3D*>(aCD);
if (!theVariables.Contains(D))
D.Nullify();
#if 0
if (D.IsNull() && complain)
cout <<name<<" does not exist"<<endl;
#endif
} }
return D;
std::cout << "Pick an object" << std::endl;
Handle(Draw_Drawable3D) aDrawable;
dout.Select (p_id, p_X, p_Y, p_b);
dout.Pick (p_id, p_X, p_Y, 5, aDrawable, 0);
if (!aDrawable.IsNull()
&& aDrawable->Name() != NULL)
{
theName = p_Name = aDrawable->Name();
}
return aDrawable;
} }
//======================================================================= //=======================================================================
//function : Get //function : Get
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean Draw::Get(const Standard_CString name, Standard_Boolean Draw::Get (const Standard_CString theName,
Standard_Real& val) Standard_Real& theValue)
{ {
if ((name[0] == '.') && (name[1] == '\0')) { if (Handle(Draw_Number) aNumber = Handle(Draw_Number)::DownCast (Draw::GetExisting (theName)))
return Standard_False; {
} theValue = aNumber->Value();
Standard_CString aName = name; return Standard_True;
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;
}
} }
return Standard_False; return Standard_False;
} }

View File

@ -92,8 +92,10 @@ static Standard_Integer OCC159bug (Draw_Interpretor& di, Standard_Integer argc,
Handle(TDocStd_Application) A = DDocStd::GetApplication(); Handle(TDocStd_Application) A = DDocStd::GetApplication();
A->Close(D); A->Close(D);
Handle(Draw_Drawable3D) DD = Draw::Get(argv[1],Standard_False); if (Handle(Draw_Drawable3D) DD = Draw::GetExisting (argv[1]))
dout.RemoveDrawable (DD); {
dout.RemoveDrawable (DD);
}
Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument(); Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument();
if (OwnerD2.IsNull()) { if (OwnerD2.IsNull()) {

View File

@ -596,7 +596,6 @@ static Standard_Integer BUC60876_ (Draw_Interpretor& di,
} }
TopoDS_Shape aShape = DBRep::Get(argv[1]); TopoDS_Shape aShape = DBRep::Get(argv[1]);
Handle(AIS_InteractiveObject) anIO = new AIS_Shape(aShape); 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); anIO->SetHilightMode((argc == 3) ? Draw::Atoi(argv[2]) : 1);
aContext->Display (anIO, Standard_True); aContext->Display (anIO, Standard_True);
return 0; return 0;

View File

@ -137,7 +137,7 @@ static Standard_Integer QADNaming_TCopyShape (Draw_Interpretor& di,
DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName); DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName);
for(;itrn.More();itrn.Next()) { for(;itrn.More();itrn.Next()) {
TCollection_AsciiString name = itrn.Value(); 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); DBRep::Set(name.ToCString(), Result);
di.AppendElement(name.ToCString()); di.AppendElement(name.ToCString());
} }

View File

@ -652,51 +652,6 @@ static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
return Standard_True; 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 //function : Clear
//purpose : Remove all the object from the viewer //purpose : Remove all the object from the viewer
@ -4458,14 +4413,15 @@ static int VDisplay2 (Draw_Interpretor& theDI,
// Display interactive objects // Display interactive objects
for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter) 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; Handle(AIS_InteractiveObject) aShape;
if (!GetMapOfAIS().Find2 (aName, aShape)) if (!GetMapOfAIS().Find2 (aName, aShape))
{ {
// create the AIS_Shape from a name // create the AIS_Shape from a name
aShape = GetAISShapeFromName (aName.ToCString()); TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
if (!aShape.IsNull()) if (!aDrawShape.IsNull())
{ {
aShape = new AIS_Shape (aDrawShape);
if (isMutable != -1) if (isMutable != -1)
{ {
aShape->SetMutable (isMutable == 1); aShape->SetMutable (isMutable == 1);
@ -4553,10 +4509,10 @@ static int VDisplay2 (Draw_Interpretor& theDI,
} }
else else
{ {
theDI << "Display " << aName.ToCString() << "\n"; theDI << "Display " << aName << "\n";
// update the Shape in the AIS_Shape // 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); Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
if (!aShapePrs.IsNull()) if (!aShapePrs.IsNull())
{ {
@ -4688,7 +4644,13 @@ static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
TCollection_AsciiString name=argv[1]; TCollection_AsciiString name=argv[1];
GetMapOfAIS().Find2(name, TheAisIO); GetMapOfAIS().Find2(name, TheAisIO);
if (TheAisIO.IsNull()) if (TheAisIO.IsNull())
TheAisIO=GetAISShapeFromName(name.ToCString()); {
TopoDS_Shape aDrawShape = DBRep::GetExisting (name);
if (!aDrawShape.IsNull())
{
TheAisIO = new AIS_Shape (aDrawShape);
}
}
if (HaveToSet) if (HaveToSet)
TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True); TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
@ -5791,42 +5753,28 @@ static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
} }
// Parse input arguments // Parse input arguments
TColStd_SequenceOfAsciiString aNamesOfIO;
for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
{ {
const TCollection_AsciiString aName = theArgVec[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; Handle(AIS_InteractiveObject) aShape;
if (!GetMapOfAIS().Find2 (aName, aShape)) if (!GetMapOfAIS().Find2 (aName, aShape))
{ {
aShape = GetAISShapeFromName (aName.ToCString()); TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
} if (!aDrawShape.IsNull())
if (!aShape.IsNull())
{
if (!GetMapOfAIS().IsBound2 (aName))
{ {
aShape = new AIS_Shape (aDrawShape);
GetMapOfAIS().Bind (aShape, aName); 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; return 0;
} }
@ -6271,10 +6219,10 @@ static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, cons
Standard_Real anAngle = 0; Standard_Real anAngle = 0;
Standard_Boolean Rev = Standard_False; Standard_Boolean Rev = Standard_False;
Standard_Integer rev = 0; Standard_Integer rev = 0;
TopoDS_Shape Solid = GetShapeFromName(argv[1]); TopoDS_Shape Solid = DBRep::Get (argv[1]);
TopoDS_Shape face = GetShapeFromName(argv[2]); TopoDS_Shape face = DBRep::Get (argv[2]);
TopoDS_Face Face = TopoDS::Face(face); TopoDS_Face Face = TopoDS::Face(face);
TopoDS_Shape Plane = GetShapeFromName(argv[3]); TopoDS_Shape Plane = DBRep::Get (argv[3]);
if (Plane.IsNull ()) { if (Plane.IsNull ()) {
di << "TEST : Plane is NULL\n"; di << "TEST : Plane is NULL\n";
return 1; return 1;

View File

@ -51,9 +51,6 @@
# include <stdio.h> # include <stdio.h>
#endif #endif
extern Handle(AIS_Shape) GetAISShapeFromName(const char* name);
static Standard_Real t3d = 1.e-4; static Standard_Real t3d = 1.e-4;
static Standard_Real t2d = 1.e-5; static Standard_Real t2d = 1.e-5;
static Standard_Real ta = 1.e-2; 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(); TopoDS_Shape res = Rakk->Shape();
DBRep::Set(a[1],res); DBRep::Set(a[1],res);
// visu resultat... // visu resultat...
Handle(AIS_Shape) AS = GetAISShapeFromName(a[1]); ViewerTest::Display (a[2], Handle(AIS_InteractiveObject)(), false);
Handle(AIS_Shape) Start = GetAISShapeFromName(a[2]); ViewerTest::Display (a[1], new AIS_Shape (res), true);
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);
return 0; return 0;
} }

View File

@ -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) static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{ {
if ( argc <4 ) { di << "ERROR: Too few args\n"; return 0; } if ( argc < 4 ) { std::cout << "Syntax error: Too few args\n"; return 1; }
Handle(DDF_Browser) browser = Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1]));
Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True)); if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; }
if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
TDF_Label lab; TDF_Label lab;
TDF_Tool::Label(browser->Data(),argv[2],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] ); Standard_Integer num = Draw::Atoi ( argv[3] );
TDF_AttributeIterator itr(lab,Standard_False); TDF_AttributeIterator itr(lab,Standard_False);
for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next(); 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(); const Handle(TDF_Attribute)& att = itr.Value();
if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) { if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {