b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
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. |
7 | // |
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. |
10 | // |
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. |
17 | |
7fd59977 |
18 | #include <XSDRAW.ixx> |
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> |
24 | #include <SWDRAW.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> |
32 | |
33 | #include <TopoDS_Shape.hxx> |
34 | #include <TransferBRep.hxx> |
35 | #include <DBRep.hxx> |
36 | |
37 | #include <Interface_Macros.hxx> |
38 | #include <stdio.h> |
39 | |
40 | #include <Message.hxx> |
41 | #include <Message_Messenger.hxx> |
fa350ff0 |
42 | #include <Message_PrinterOStream.hxx> |
43 | #include <Draw_Printer.hxx> |
7fd59977 |
44 | |
45 | static int deja = 0, dejald = 0; |
46 | //unused variable |
47 | //static int okxset = 0; |
48 | |
49 | static Handle(Dico_DictionaryOfInteger) theolds; |
50 | static Handle(TColStd_HSequenceOfAsciiString) thenews; |
51 | |
52 | static Handle(IFSelect_SessionPilot) thepilot; // detient Session, Model |
53 | |
54 | static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
55 | { |
56 | TCollection_AsciiString mess; |
57 | for (Standard_Integer i = 0; i < argc; i ++) { |
58 | mess.AssignCat(argv[i]); mess.AssignCat(" "); |
59 | } |
60 | |
61 | IFSelect_ReturnStatus stat = thepilot->Execute (mess.ToCString()); |
62 | if (stat == IFSelect_RetError || stat == IFSelect_RetFail) return 1; |
63 | else return 0; |
64 | } |
65 | |
66 | void XSDRAW::ChangeCommand |
67 | (const Standard_CString oldname, const Standard_CString newname) |
68 | { |
69 | if (theolds.IsNull()) theolds = new Dico_DictionaryOfInteger; |
70 | Standard_Integer num = 0; |
71 | if (newname[0] != '\0') { |
72 | if (thenews.IsNull()) thenews = new TColStd_HSequenceOfAsciiString(); |
73 | TCollection_AsciiString newstr(newname); |
74 | thenews->Append(newstr); |
75 | num = thenews->Length(); |
76 | } |
77 | theolds->SetItem (oldname,num); |
78 | } |
79 | |
80 | void XSDRAW::RemoveCommand |
81 | (const Standard_CString oldname) |
82 | { |
83 | ChangeCommand (oldname,""); |
84 | } |
85 | |
86 | Standard_Boolean XSDRAW::LoadSession () |
87 | { |
88 | if (deja) return Standard_False; |
89 | deja = 1; |
90 | thepilot = new IFSelect_SessionPilot("XSTEP-DRAW>"); |
91 | Handle(XSControl_WorkSession) WS = new XSControl_WorkSession; |
92 | WS->SetVars (new XSDRAW_Vars); |
93 | thepilot->SetSession (WS); |
94 | |
95 | IFSelect_Functions::Init(); |
96 | XSControl_Functions::Init(); |
97 | XSControl_FuncShape::Init(); |
98 | // XSDRAW_Shape::Init(); passe a present par theCommands |
99 | return Standard_True; |
100 | } |
101 | |
102 | void XSDRAW::LoadDraw (Draw_Interpretor& theCommands) |
103 | { |
104 | if (dejald) return; dejald = 1; |
105 | // XSDRAW_Shape::InitCommands (theCommands); |
106 | // Pour tout faire d un coup : BRepTest & cie, SWDRAW & cie : |
107 | SWDRAW::Init (theCommands); |
108 | LoadSession(); |
109 | |
110 | //skl: we make remove commands "x" and "exit" in order to this commands are |
111 | // performed not in IFSelect_SessionPilot but in standard Tcl interpretor |
112 | XSDRAW::RemoveCommand("x"); |
113 | XSDRAW::RemoveCommand("exit"); |
fa350ff0 |
114 | const Handle(Message_Messenger) &sout = Message::DefaultMessenger(); |
115 | if (!sout.IsNull()){ |
116 | sout->RemovePrinters(STANDARD_TYPE(Message_PrinterOStream)); |
117 | sout->AddPrinter(new Draw_Printer(theCommands)); |
118 | } |
7fd59977 |
119 | // if (!getenv("WBHOSTTOP")) XSDRAW::RemoveCommand("xsnew"); |
120 | Handle(TColStd_HSequenceOfAsciiString) list = |
121 | IFSelect_Activator::Commands(0); |
122 | TCollection_AsciiString com; |
123 | Standard_Integer i, nb = list->Length(); |
124 | for (i = 1; i <= nb; i ++) { |
125 | Handle(IFSelect_Activator) act; |
126 | Standard_Integer nact, num = -1; |
127 | char help[200]; |
128 | com = list->Value(i); |
129 | if (!theolds.IsNull()) |
130 | if (theolds->HasItem(com.ToCString())) num = theolds->Item(com.ToCString()); |
131 | if (num == 0) continue; |
132 | if (!IFSelect_Activator::Select(com.ToCString(),nact,act)) |
91322f44 |
133 | Sprintf (help,"type : xhelp %s for help",com.ToCString()); |
7fd59977 |
134 | else if (!act.IsNull()) strcpy(help,act->Help(nact)); |
135 | if (num < 0) theCommands.Add (com.ToCString(),help,XSTEPDRAWRUN,act->Group()); |
136 | else theCommands.Add (thenews->Value(num).ToCString(),help,XSTEPDRAWRUN,act->Group()); |
137 | } |
138 | } |
139 | |
140 | Standard_Integer XSDRAW::Execute |
141 | (const Standard_CString command, const Standard_CString varname) |
142 | { |
143 | char mess[100]; |
91322f44 |
144 | Sprintf (mess,command,varname); |
302f96fb |
145 | thepilot->Execute (mess); |
7fd59977 |
146 | return 1; // stat ? |
147 | } |
148 | |
149 | Handle(IFSelect_SessionPilot) XSDRAW::Pilot () |
150 | { return thepilot; } |
151 | |
152 | Handle(XSControl_WorkSession) XSDRAW::Session () |
153 | { return XSControl::Session(thepilot); } |
154 | |
155 | void XSDRAW::SetController (const Handle(XSControl_Controller)& control) |
156 | { |
157 | if (thepilot.IsNull()) XSDRAW::LoadSession(); |
158 | if (control.IsNull()) cout<<"XSTEP Controller not defined"<<endl; |
159 | else if (!Session().IsNull()) Session()->SetController (control); |
160 | else cout<<"XSTEP Session badly or not defined"<<endl; |
161 | } |
162 | |
163 | |
164 | Handle(XSControl_Controller) XSDRAW::Controller () |
165 | { return Session()->NormAdaptor(); } |
166 | |
167 | Standard_Boolean XSDRAW::SetNorm |
168 | (const Standard_CString norm, const Standard_CString profile) |
169 | { |
170 | Standard_Boolean stat = Session()->SelectNorm (norm,profile); |
171 | if (stat) IFSelect_Activator::SetCurrentAlias (Session()->SelectedNorm(Standard_True)); |
172 | return stat; |
173 | } |
174 | |
175 | Handle(Interface_Protocol) XSDRAW::Protocol () |
176 | { return thepilot->Session()->Protocol(); } |
177 | |
178 | Handle(Interface_InterfaceModel) XSDRAW::Model () |
179 | { return thepilot->Session()->Model(); } |
180 | |
181 | void XSDRAW::SetModel |
182 | (const Handle(Interface_InterfaceModel)& model, const Standard_CString file) |
183 | { |
184 | thepilot->Session()->SetModel(model); |
185 | if (file && file[0] != '\0') thepilot->Session()->SetLoadedFile(file); |
186 | } |
187 | |
188 | Handle(Interface_InterfaceModel) XSDRAW::NewModel () |
189 | { return Session()->NewModel(); } |
190 | |
191 | Handle(Standard_Transient) XSDRAW::Entity (const Standard_Integer num) |
192 | { return thepilot->Session()->StartingEntity(num); } |
193 | |
194 | Standard_Integer XSDRAW::Number (const Handle(Standard_Transient)& ent) |
195 | { return thepilot->Session()->StartingNumber(ent); } |
196 | |
197 | void XSDRAW::SetTransferProcess (const Handle(Standard_Transient)& ATP) |
198 | { |
199 | DeclareAndCast(Transfer_FinderProcess,FP,ATP); |
200 | DeclareAndCast(Transfer_TransientProcess,TP,ATP); |
201 | |
202 | // Cas FinderProcess ==> TransferWriter |
203 | if (!FP.IsNull()) Session()->SetMapWriter(FP); |
204 | |
205 | // Cas TransientProcess ==> TransferReader |
206 | if (!TP.IsNull()) { |
207 | if (!TP->Model().IsNull() && TP->Model() != Session()->Model()) |
208 | Session()->SetModel (TP->Model()); |
209 | Session()->SetMapReader(TP); |
210 | } |
211 | } |
212 | |
213 | Handle(Transfer_TransientProcess) XSDRAW::TransientProcess () |
214 | { return Session()->TransferReader()->TransientProcess(); } |
215 | |
216 | Handle(Transfer_FinderProcess) XSDRAW::FinderProcess () |
217 | { return Session()->TransferWriter()->FinderProcess(); } |
218 | |
219 | |
220 | void XSDRAW::InitTransferReader (const Standard_Integer mode) |
221 | { |
222 | // 0 nullify 1 clear |
223 | // 2 init TR avec contenu TP (roots) 3 init TP avec contenu TR |
224 | // 4 init avec model (debut scratch) |
225 | Session()->InitTransferReader(mode); |
226 | } |
227 | |
228 | Handle(XSControl_TransferReader) XSDRAW::TransferReader () |
229 | { return Session()->TransferReader(); } |
230 | |
231 | |
232 | // ############ AUXILIAIRES ############# |
233 | |
234 | Handle(Standard_Transient) XSDRAW::GetEntity (const Standard_CString name) |
235 | { return IFSelect_Functions::GiveEntity (Session(),name); } |
236 | |
237 | Standard_Integer XSDRAW::GetEntityNumber (const Standard_CString name) |
238 | { return IFSelect_Functions::GiveEntityNumber (Session(),name); } |
239 | |
240 | |
241 | Handle(TColStd_HSequenceOfTransient) XSDRAW::GetList |
242 | (const Standard_CString first, const Standard_CString second) |
243 | { |
244 | Handle(TColStd_HSequenceOfTransient) list; |
245 | if (!first || first[0] == '\0') { |
246 | char ligne[80]; ligne[0] = '\0'; char truc; |
247 | // cin.clear(); cin.get (ligne,79,'\n'); |
60be1f9b |
248 | cin >> ligne; Standard_Size ln = strlen(ligne); |
7fd59977 |
249 | char *ff = &ligne[0], *ss = NULL; |
250 | cin.get(truc); if (truc != '\n') { cin>>&ligne[ln+1]; ss = &ligne[ln+1]; } |
251 | return XSDRAW::GetList (ff,ss); |
252 | } |
253 | // return IFSelect_Functions::GiveList (Session(),first,second); |
254 | return IFSelect_Functions::GiveList (Session(),first,second); |
255 | } |
256 | |
257 | |
258 | Standard_Boolean XSDRAW::FileAndVar |
259 | (const Standard_CString file, const Standard_CString var, |
260 | const Standard_CString def, |
261 | TCollection_AsciiString& resfile, TCollection_AsciiString& resvar) |
262 | { return XSControl_FuncShape::FileAndVar |
263 | (XSDRAW::Session(),file,var,def,resfile,resvar); } |
264 | |
265 | Standard_Integer XSDRAW::MoreShapes |
266 | (Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name) |
267 | { return XSControl_FuncShape::MoreShapes (XSDRAW::Session(),list,name); } |
268 | |
269 | |
270 | // FONCTION POUR LE DEBUG |
271 | |
272 | Standard_Integer XSDRAW_WHAT (const Handle_Standard_Transient& ent) |
273 | { |
274 | if (ent.IsNull()) { cout<<"(Null Handle)"<<endl; return 0; } |
275 | Handle(Interface_InterfaceModel) model = XSDRAW::Model(); |
276 | if (model.IsNull()) { cout<<"(No model) Type:"<<ent->DynamicType()->Name()<<endl; return 0; } |
277 | cout<<" Num/Id :"; |
278 | model->Print (ent, Message::DefaultMessenger(), 0); |
279 | cout<<" -- Recorded Type:"<<model->TypeName (ent)<<endl; |
280 | return model->Number(ent); |
281 | } |