1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
19 #include <Dico_DictionaryOfInteger.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <TColStd_HSequenceOfAsciiString.hxx>
22 #include <IFSelect_Functions.hxx>
23 #include <IFSelect_SessionPilot.hxx>
25 //#include <XSDRAW_Shape.hxx>
26 #include <XSDRAW_Vars.hxx>
27 #include <XSControl_Functions.hxx>
28 #include <XSControl_FuncShape.hxx>
29 #include <Draw_Appli.hxx>
30 #include <XSControl.hxx>
31 #include <XSControl_TransferWriter.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TransferBRep.hxx>
37 #include <Interface_Macros.hxx>
40 #include <Message.hxx>
41 #include <Message_Messenger.hxx>
43 static int deja = 0, dejald = 0;
45 //static int okxset = 0;
47 static Handle(Dico_DictionaryOfInteger) theolds;
48 static Handle(TColStd_HSequenceOfAsciiString) thenews;
50 static Handle(IFSelect_SessionPilot) thepilot; // detient Session, Model
52 static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& , Standard_Integer argc, const char** argv)
54 TCollection_AsciiString mess;
55 for (Standard_Integer i = 0; i < argc; i ++) {
56 mess.AssignCat(argv[i]); mess.AssignCat(" ");
59 IFSelect_ReturnStatus stat = thepilot->Execute (mess.ToCString());
60 if (stat == IFSelect_RetError || stat == IFSelect_RetFail) return 1;
64 void XSDRAW::ChangeCommand
65 (const Standard_CString oldname, const Standard_CString newname)
67 if (theolds.IsNull()) theolds = new Dico_DictionaryOfInteger;
68 Standard_Integer num = 0;
69 if (newname[0] != '\0') {
70 if (thenews.IsNull()) thenews = new TColStd_HSequenceOfAsciiString();
71 TCollection_AsciiString newstr(newname);
72 thenews->Append(newstr);
73 num = thenews->Length();
75 theolds->SetItem (oldname,num);
78 void XSDRAW::RemoveCommand
79 (const Standard_CString oldname)
81 ChangeCommand (oldname,"");
84 Standard_Boolean XSDRAW::LoadSession ()
86 if (deja) return Standard_False;
88 thepilot = new IFSelect_SessionPilot("XSTEP-DRAW>");
89 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
90 WS->SetVars (new XSDRAW_Vars);
91 thepilot->SetSession (WS);
93 IFSelect_Functions::Init();
94 XSControl_Functions::Init();
95 XSControl_FuncShape::Init();
96 // XSDRAW_Shape::Init(); passe a present par theCommands
100 void XSDRAW::LoadDraw (Draw_Interpretor& theCommands)
102 if (dejald) return; dejald = 1;
103 // XSDRAW_Shape::InitCommands (theCommands);
104 // Pour tout faire d un coup : BRepTest & cie, SWDRAW & cie :
105 SWDRAW::Init (theCommands);
108 //skl: we make remove commands "x" and "exit" in order to this commands are
109 // performed not in IFSelect_SessionPilot but in standard Tcl interpretor
110 XSDRAW::RemoveCommand("x");
111 XSDRAW::RemoveCommand("exit");
112 // if (!getenv("WBHOSTTOP")) XSDRAW::RemoveCommand("xsnew");
113 Handle(TColStd_HSequenceOfAsciiString) list =
114 IFSelect_Activator::Commands(0);
115 TCollection_AsciiString com;
116 Standard_Integer i, nb = list->Length();
117 for (i = 1; i <= nb; i ++) {
118 Handle(IFSelect_Activator) act;
119 Standard_Integer nact, num = -1;
121 com = list->Value(i);
122 if (!theolds.IsNull())
123 if (theolds->HasItem(com.ToCString())) num = theolds->Item(com.ToCString());
124 if (num == 0) continue;
125 if (!IFSelect_Activator::Select(com.ToCString(),nact,act))
126 sprintf (help,"type : xhelp %s for help",com.ToCString());
127 else if (!act.IsNull()) strcpy(help,act->Help(nact));
128 if (num < 0) theCommands.Add (com.ToCString(),help,XSTEPDRAWRUN,act->Group());
129 else theCommands.Add (thenews->Value(num).ToCString(),help,XSTEPDRAWRUN,act->Group());
133 Standard_Integer XSDRAW::Execute
134 (const Standard_CString command, const Standard_CString varname)
137 sprintf (mess,command,varname);
139 IFSelect_ReturnStatus stat =
141 thepilot->Execute (mess);
145 Handle(IFSelect_SessionPilot) XSDRAW::Pilot ()
148 Handle(XSControl_WorkSession) XSDRAW::Session ()
149 { return XSControl::Session(thepilot); }
151 void XSDRAW::SetController (const Handle(XSControl_Controller)& control)
153 if (thepilot.IsNull()) XSDRAW::LoadSession();
154 if (control.IsNull()) cout<<"XSTEP Controller not defined"<<endl;
155 else if (!Session().IsNull()) Session()->SetController (control);
156 else cout<<"XSTEP Session badly or not defined"<<endl;
160 Handle(XSControl_Controller) XSDRAW::Controller ()
161 { return Session()->NormAdaptor(); }
163 Standard_Boolean XSDRAW::SetNorm
164 (const Standard_CString norm, const Standard_CString profile)
166 Standard_Boolean stat = Session()->SelectNorm (norm,profile);
167 if (stat) IFSelect_Activator::SetCurrentAlias (Session()->SelectedNorm(Standard_True));
171 Handle(Interface_Protocol) XSDRAW::Protocol ()
172 { return thepilot->Session()->Protocol(); }
174 Handle(Interface_InterfaceModel) XSDRAW::Model ()
175 { return thepilot->Session()->Model(); }
177 void XSDRAW::SetModel
178 (const Handle(Interface_InterfaceModel)& model, const Standard_CString file)
180 thepilot->Session()->SetModel(model);
181 if (file && file[0] != '\0') thepilot->Session()->SetLoadedFile(file);
184 Handle(Interface_InterfaceModel) XSDRAW::NewModel ()
185 { return Session()->NewModel(); }
187 Handle(Standard_Transient) XSDRAW::Entity (const Standard_Integer num)
188 { return thepilot->Session()->StartingEntity(num); }
190 Standard_Integer XSDRAW::Number (const Handle(Standard_Transient)& ent)
191 { return thepilot->Session()->StartingNumber(ent); }
193 void XSDRAW::SetTransferProcess (const Handle(Standard_Transient)& ATP)
195 DeclareAndCast(Transfer_FinderProcess,FP,ATP);
196 DeclareAndCast(Transfer_TransientProcess,TP,ATP);
198 // Cas FinderProcess ==> TransferWriter
199 if (!FP.IsNull()) Session()->SetMapWriter(FP);
201 // Cas TransientProcess ==> TransferReader
203 if (!TP->Model().IsNull() && TP->Model() != Session()->Model())
204 Session()->SetModel (TP->Model());
205 Session()->SetMapReader(TP);
209 Handle(Transfer_TransientProcess) XSDRAW::TransientProcess ()
210 { return Session()->TransferReader()->TransientProcess(); }
212 Handle(Transfer_FinderProcess) XSDRAW::FinderProcess ()
213 { return Session()->TransferWriter()->FinderProcess(); }
216 void XSDRAW::InitTransferReader (const Standard_Integer mode)
219 // 2 init TR avec contenu TP (roots) 3 init TP avec contenu TR
220 // 4 init avec model (debut scratch)
221 Session()->InitTransferReader(mode);
224 Handle(XSControl_TransferReader) XSDRAW::TransferReader ()
225 { return Session()->TransferReader(); }
228 // ############ AUXILIAIRES #############
230 Handle(Standard_Transient) XSDRAW::GetEntity (const Standard_CString name)
231 { return IFSelect_Functions::GiveEntity (Session(),name); }
233 Standard_Integer XSDRAW::GetEntityNumber (const Standard_CString name)
234 { return IFSelect_Functions::GiveEntityNumber (Session(),name); }
237 Handle(TColStd_HSequenceOfTransient) XSDRAW::GetList
238 (const Standard_CString first, const Standard_CString second)
240 Handle(TColStd_HSequenceOfTransient) list;
241 if (!first || first[0] == '\0') {
242 char ligne[80]; ligne[0] = '\0'; char truc;
243 // cin.clear(); cin.get (ligne,79,'\n');
244 cin >> ligne; Standard_Size ln = strlen(ligne);
245 char *ff = &ligne[0], *ss = NULL;
246 cin.get(truc); if (truc != '\n') { cin>>&ligne[ln+1]; ss = &ligne[ln+1]; }
247 return XSDRAW::GetList (ff,ss);
249 // return IFSelect_Functions::GiveList (Session(),first,second);
250 return IFSelect_Functions::GiveList (Session(),first,second);
254 Standard_Boolean XSDRAW::FileAndVar
255 (const Standard_CString file, const Standard_CString var,
256 const Standard_CString def,
257 TCollection_AsciiString& resfile, TCollection_AsciiString& resvar)
258 { return XSControl_FuncShape::FileAndVar
259 (XSDRAW::Session(),file,var,def,resfile,resvar); }
261 Standard_Integer XSDRAW::MoreShapes
262 (Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name)
263 { return XSControl_FuncShape::MoreShapes (XSDRAW::Session(),list,name); }
266 // FONCTION POUR LE DEBUG
268 Standard_Integer XSDRAW_WHAT (const Handle_Standard_Transient& ent)
270 if (ent.IsNull()) { cout<<"(Null Handle)"<<endl; return 0; }
271 Handle(Interface_InterfaceModel) model = XSDRAW::Model();
272 if (model.IsNull()) { cout<<"(No model) Type:"<<ent->DynamicType()->Name()<<endl; return 0; }
274 model->Print (ent, Message::DefaultMessenger(), 0);
275 cout<<" -- Recorded Type:"<<model->TypeName (ent)<<endl;
276 return model->Number(ent);