1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Dico_DictionaryOfInteger.hxx>
16 #include <TCollection_AsciiString.hxx>
17 #include <TColStd_HSequenceOfAsciiString.hxx>
18 #include <IFSelect_Functions.hxx>
19 #include <IFSelect_SessionPilot.hxx>
20 //#include <XSDRAW_Shape.hxx>
21 #include <XSDRAW_Vars.hxx>
22 #include <XSControl_Functions.hxx>
23 #include <XSControl_FuncShape.hxx>
24 #include <Draw_Appli.hxx>
25 #include <XSControl.hxx>
26 #include <XSControl_TransferWriter.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TransferBRep.hxx>
32 #include <Interface_Macros.hxx>
35 #include <Message.hxx>
37 static int deja = 0, dejald = 0;
39 //static int okxset = 0;
41 static Handle(Dico_DictionaryOfInteger) theolds;
42 static Handle(TColStd_HSequenceOfAsciiString) thenews;
44 static Handle(IFSelect_SessionPilot) thepilot; // detient Session, Model
46 static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& , Standard_Integer argc, const char** argv)
48 TCollection_AsciiString mess;
49 for (Standard_Integer i = 0; i < argc; i ++) {
50 mess.AssignCat(argv[i]); mess.AssignCat(" ");
53 IFSelect_ReturnStatus stat = thepilot->Execute (mess.ToCString());
54 if (stat == IFSelect_RetError || stat == IFSelect_RetFail) return 1;
58 void XSDRAW::ChangeCommand
59 (const Standard_CString oldname, const Standard_CString newname)
61 if (theolds.IsNull()) theolds = new Dico_DictionaryOfInteger;
62 Standard_Integer num = 0;
63 if (newname[0] != '\0') {
64 if (thenews.IsNull()) thenews = new TColStd_HSequenceOfAsciiString();
65 TCollection_AsciiString newstr(newname);
66 thenews->Append(newstr);
67 num = thenews->Length();
69 theolds->SetItem (oldname,num);
72 void XSDRAW::RemoveCommand
73 (const Standard_CString oldname)
75 ChangeCommand (oldname,"");
78 Standard_Boolean XSDRAW::LoadSession ()
80 if (deja) return Standard_False;
82 thepilot = new IFSelect_SessionPilot("XSTEP-DRAW>");
83 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
84 WS->SetVars (new XSDRAW_Vars);
85 thepilot->SetSession (WS);
87 IFSelect_Functions::Init();
88 XSControl_Functions::Init();
89 XSControl_FuncShape::Init();
90 // XSDRAW_Shape::Init(); passe a present par theCommands
94 void XSDRAW::LoadDraw (Draw_Interpretor& theCommands)
96 if (dejald) return; dejald = 1;
97 // Pour tout faire d un coup : BRepTest & cie:
100 //skl: we make remove commands "x" and "exit" in order to this commands are
101 // performed not in IFSelect_SessionPilot but in standard Tcl interpretor
102 XSDRAW::RemoveCommand("x");
103 XSDRAW::RemoveCommand("exit");
105 // if (!getenv("WBHOSTTOP")) XSDRAW::RemoveCommand("xsnew");
106 Handle(TColStd_HSequenceOfAsciiString) list =
107 IFSelect_Activator::Commands(0);
108 TCollection_AsciiString com;
109 Standard_Integer i, nb = list->Length();
110 for (i = 1; i <= nb; i ++) {
111 Handle(IFSelect_Activator) act;
112 Standard_Integer nact, num = -1;
114 com = list->Value(i);
115 if (!theolds.IsNull())
116 if (theolds->HasItem(com.ToCString())) num = theolds->Item(com.ToCString());
117 if (num == 0) continue;
118 if (!IFSelect_Activator::Select(com.ToCString(),nact,act))
119 Sprintf (help,"type : xhelp %s for help",com.ToCString());
120 else if (!act.IsNull()) strcpy(help,act->Help(nact));
121 if (num < 0) theCommands.Add (com.ToCString(),help,XSTEPDRAWRUN,act->Group());
122 else theCommands.Add (thenews->Value(num).ToCString(),help,XSTEPDRAWRUN,act->Group());
126 Standard_Integer XSDRAW::Execute
127 (const Standard_CString command, const Standard_CString varname)
130 Sprintf (mess,command,varname);
131 thepilot->Execute (mess);
135 Handle(IFSelect_SessionPilot) XSDRAW::Pilot ()
138 Handle(XSControl_WorkSession) XSDRAW::Session ()
139 { return XSControl::Session(thepilot); }
141 void XSDRAW::SetController (const Handle(XSControl_Controller)& control)
143 if (thepilot.IsNull()) XSDRAW::LoadSession();
144 if (control.IsNull()) cout<<"XSTEP Controller not defined"<<endl;
145 else if (!Session().IsNull()) Session()->SetController (control);
146 else cout<<"XSTEP Session badly or not defined"<<endl;
150 Handle(XSControl_Controller) XSDRAW::Controller ()
151 { return Session()->NormAdaptor(); }
153 Standard_Boolean XSDRAW::SetNorm
154 (const Standard_CString norm, const Standard_CString profile)
156 Standard_Boolean stat = Session()->SelectNorm (norm,profile);
157 if (stat) IFSelect_Activator::SetCurrentAlias (Session()->SelectedNorm(Standard_True));
161 Handle(Interface_Protocol) XSDRAW::Protocol ()
162 { return thepilot->Session()->Protocol(); }
164 Handle(Interface_InterfaceModel) XSDRAW::Model ()
165 { return thepilot->Session()->Model(); }
167 void XSDRAW::SetModel
168 (const Handle(Interface_InterfaceModel)& model, const Standard_CString file)
170 thepilot->Session()->SetModel(model);
171 if (file && file[0] != '\0') thepilot->Session()->SetLoadedFile(file);
174 Handle(Interface_InterfaceModel) XSDRAW::NewModel ()
175 { return Session()->NewModel(); }
177 Handle(Standard_Transient) XSDRAW::Entity (const Standard_Integer num)
178 { return thepilot->Session()->StartingEntity(num); }
180 Standard_Integer XSDRAW::Number (const Handle(Standard_Transient)& ent)
181 { return thepilot->Session()->StartingNumber(ent); }
183 void XSDRAW::SetTransferProcess (const Handle(Standard_Transient)& ATP)
185 DeclareAndCast(Transfer_FinderProcess,FP,ATP);
186 DeclareAndCast(Transfer_TransientProcess,TP,ATP);
188 // Cas FinderProcess ==> TransferWriter
189 if (!FP.IsNull()) Session()->SetMapWriter(FP);
191 // Cas TransientProcess ==> TransferReader
193 if (!TP->Model().IsNull() && TP->Model() != Session()->Model())
194 Session()->SetModel (TP->Model());
195 Session()->SetMapReader(TP);
199 Handle(Transfer_TransientProcess) XSDRAW::TransientProcess ()
200 { return Session()->TransferReader()->TransientProcess(); }
202 Handle(Transfer_FinderProcess) XSDRAW::FinderProcess ()
203 { return Session()->TransferWriter()->FinderProcess(); }
206 void XSDRAW::InitTransferReader (const Standard_Integer mode)
209 // 2 init TR avec contenu TP (roots) 3 init TP avec contenu TR
210 // 4 init avec model (debut scratch)
211 Session()->InitTransferReader(mode);
214 Handle(XSControl_TransferReader) XSDRAW::TransferReader ()
215 { return Session()->TransferReader(); }
218 // ############ AUXILIAIRES #############
220 Handle(Standard_Transient) XSDRAW::GetEntity (const Standard_CString name)
221 { return IFSelect_Functions::GiveEntity (Session(),name); }
223 Standard_Integer XSDRAW::GetEntityNumber (const Standard_CString name)
224 { return IFSelect_Functions::GiveEntityNumber (Session(),name); }
227 Handle(TColStd_HSequenceOfTransient) XSDRAW::GetList
228 (const Standard_CString first, const Standard_CString second)
230 Handle(TColStd_HSequenceOfTransient) list;
231 if (!first || first[0] == '\0') {
232 char ligne[80]; ligne[0] = '\0'; char truc;
233 // cin.clear(); cin.get (ligne,79,'\n');
234 cin >> ligne; Standard_Size ln = strlen(ligne);
235 char *ff = &ligne[0], *ss = NULL;
236 cin.get(truc); if (truc != '\n') { cin>>&ligne[ln+1]; ss = &ligne[ln+1]; }
237 return XSDRAW::GetList (ff,ss);
239 // return IFSelect_Functions::GiveList (Session(),first,second);
240 return IFSelect_Functions::GiveList (Session(),first,second);
244 Standard_Boolean XSDRAW::FileAndVar
245 (const Standard_CString file, const Standard_CString var,
246 const Standard_CString def,
247 TCollection_AsciiString& resfile, TCollection_AsciiString& resvar)
248 { return XSControl_FuncShape::FileAndVar
249 (XSDRAW::Session(),file,var,def,resfile,resvar); }
251 Standard_Integer XSDRAW::MoreShapes
252 (Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name)
253 { return XSControl_FuncShape::MoreShapes (XSDRAW::Session(),list,name); }
256 // FONCTION POUR LE DEBUG
258 Standard_Integer XSDRAW_WHAT (const Handle(Standard_Transient)& ent)
260 if (ent.IsNull()) { cout<<"(Null Handle)"<<endl; return 0; }
261 Handle(Interface_InterfaceModel) model = XSDRAW::Model();
262 if (model.IsNull()) { cout<<"(No model) Type:"<<ent->DynamicType()->Name()<<endl; return 0; }
264 model->Print (ent, Message::DefaultMessenger(), 0);
265 cout<<" -- Recorded Type:"<<model->TypeName (ent)<<endl;
266 return model->Number(ent);