1 // Created on: 1995-02-23
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Draw_Appli.hxx>
19 #include <Draw_Axis2D.hxx>
20 #include <Draw_Axis3D.hxx>
21 #include <Draw_Display.hxx>
22 #include <Draw_Drawable3D.hxx>
23 #include <Draw_Grid.hxx>
24 #include <Draw_Number.hxx>
25 #include <Draw_ProgressIndicator.hxx>
26 #include <Draw_SequenceOfDrawable3D.hxx>
27 #include <Message.hxx>
28 #include <NCollection_Array1.hxx>
29 #include <NCollection_Map.hxx>
30 #include <Standard_SStream.hxx>
31 #include <Standard_Stream.hxx>
32 #include <Standard_NotImplemented.hxx>
33 #include <TCollection_AsciiString.hxx>
37 extern Draw_Viewer dout;
43 #include <OSD_Environment.hxx>
44 #include <OSD_FileSystem.hxx>
45 #include <OSD_OpenFile.hxx>
47 Standard_Boolean Draw_ParseFailed = Standard_True;
49 static Standard_Boolean autodisp = Standard_True;
50 static Standard_Boolean repaint2d = Standard_False, repaint3d = Standard_False;
52 //! Returns dictionary of variables
53 //! Variables are stored in a map Integer, Transient.
54 //! The Integer Value is the content of the Tcl variable.
55 static NCollection_Map<Handle(Draw_Drawable3D)>& Draw_changeDrawables()
57 static NCollection_Map<Handle(Draw_Drawable3D)> theVariables;
61 //=======================================================================
62 //function : FindVariable
64 //=======================================================================
66 static Standard_Integer p_id = 0;
67 static Standard_Integer p_X = 0;
68 static Standard_Integer p_Y = 0;
69 static Standard_Integer p_b = 0;
70 static const char* p_Name = "";
72 //=======================================================================
74 //=======================================================================
75 static Standard_Integer save (Draw_Interpretor& theDI,
76 Standard_Integer theNbArgs,
77 const char** theArgVec)
81 theDI << "Syntax error: wrong number of arguments!\n";
82 theDI.PrintHelp (theArgVec[0]);
86 Handle(Draw_Drawable3D) aDrawable = Draw::Get (theArgVec[1]);
87 if (aDrawable.IsNull())
89 theDI << "Syntax error: '" << theArgVec[1] << "' is not a drawable";
93 const char* aName = theArgVec[2];
94 const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
95 std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (aName, std::ios::out);
96 aStream->precision (15);
97 if (aStream.get() == NULL || !aStream->good())
99 theDI << "Error: cannot open file for writing " << aName;
105 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
106 Standard_CString aToolTypeName = aDrawable->DynamicType()->Name();
107 *aStream << aToolTypeName << "\n";
108 Draw::SetProgressBar (aProgress);
109 aDrawable->Save (*aStream);
111 catch (const Standard_NotImplemented& )
113 theDI << "Error: no method for saving " << theArgVec[1];
118 Draw::SetProgressBar (Handle(Draw_ProgressIndicator)());
121 const Standard_Boolean aRes = aStream->good() && !errno;
124 theDI << "Error: file has not been written";
128 theDI << theArgVec[1];
132 //=======================================================================
134 //=======================================================================
135 static Standard_Integer restore (Draw_Interpretor& theDI,
136 Standard_Integer theNbArgs,
137 const char** theArgVec)
144 const char* aFileName = theArgVec[1];
145 const char* aVarName = theArgVec[2];
147 const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
148 std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (aFileName, std::ios::in);
149 if (aStream.get() == NULL)
151 theDI << "Error: cannot open file for reading: '" << aFileName << "'";
154 char aType[255] = {};
158 theDI << "Error: cannot read file: '" << aFileName << "'";
163 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
164 Draw::SetProgressBar (aProgress);
165 Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, *aStream);
166 if (aDrawable.IsNull())
168 // assume that this file stores a DBRep_DrawableShape variable
169 aStream->seekg (0, std::ios::beg);
170 aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", *aStream);
172 if (aDrawable.IsNull())
174 theDI << "Error: cannot restore a " << aType;
178 Draw::Set (aVarName, aDrawable, aDrawable->IsDisplayable() && autodisp);
179 Draw::SetProgressBar (Handle(Draw_ProgressIndicator)());
186 //=======================================================================
188 //=======================================================================
190 static Standard_Integer display(Draw_Interpretor& di, Standard_Integer n, const char** a)
192 if (n <= 1) return 1;
194 for (Standard_Integer i = 1; i < n; i++) {
195 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
207 //=======================================================================
208 // erase, clear, donly
209 //=======================================================================
211 static Standard_Integer erase(Draw_Interpretor& di, Standard_Integer n, const char** a)
213 static Standard_Boolean draw_erase_mute = Standard_False;
215 if (!strcasecmp(a[1],"-mute")) {
216 draw_erase_mute = Standard_True;
221 Standard_Boolean donly = !strcasecmp(a[0],"donly");
223 if (n <= 1 || donly) {
224 // clear, 2dclear, donly, erase (without arguments)
227 // solve the names for "." before erasing
229 for (i = 1; i < n; i++) {
230 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
232 if ((a[i][0] == '.') && (a[i][1] == '\0'))
233 std::cout << "Missed !!!" << std::endl;
239 // sauvegarde des proteges visibles
240 Draw_SequenceOfDrawable3D prot;
241 for (NCollection_Map<Handle(Draw_Drawable3D)>::Iterator aMapIt (Draw::Drawables()); aMapIt.More(); aMapIt.Next())
243 const Handle(Draw_Drawable3D)& D = aMapIt.Key();
246 if (D->Protected() && D->Visible())
253 // effacement de toutes les variables
254 Standard_Integer erasemode = 1;
255 if (a[0][0] == '2') erasemode = 2;
256 if (a[0][0] == 'c') erasemode = 3;
258 // effacement des graphiques non variables
261 else if (erasemode == 3)
266 // affichage pour donly
268 for (i = 1; i < n; i++) {
269 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
273 if (!draw_erase_mute) di << a[i] << " ";
279 // afficahge des proteges
280 for (i = 1; i <= prot.Length(); i++)
286 for (Standard_Integer i = 1; i < n; i++) {
287 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
290 dout.RemoveDrawable(D);
291 if (!draw_erase_mute) di << D->Name() << " ";
298 draw_erase_mute = Standard_False;
299 repaint2d = Standard_False;
300 repaint3d = Standard_False;
307 //=======================================================================
309 //=======================================================================
311 static Standard_Integer draw(Draw_Interpretor& , Standard_Integer n, const char** a)
314 Standard_Integer id = Draw::Atoi(a[1]);
315 if (!dout.HasView(id)) {
316 Message::SendFail() << "bad view number in draw";
319 Standard_Integer mo = Draw::Atoi(a[2]);
320 Draw_Display d = dout.MakeDisplay(id);
323 for (i = 3; i < n; i++) {
324 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
325 if (!D.IsNull()) D->DrawOn(d);
331 //=======================================================================
332 // protect, unprotect
333 //=======================================================================
335 static Standard_Integer protect(Draw_Interpretor& di, Standard_Integer n, const char** a)
337 if (n <= 1) return 1;
338 Standard_Boolean prot = *a[0] != 'u';
339 for (Standard_Integer i = 1; i < n; i++) {
340 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
349 //=======================================================================
351 //=======================================================================
353 static Standard_Integer autodisplay(Draw_Interpretor& di, Standard_Integer n, const char** a)
356 autodisp = !autodisp;
358 autodisp = !(!strcasecmp(a[1],"0"));
369 //=======================================================================
371 //=======================================================================
373 static Standard_Integer whatis(Draw_Interpretor& di, Standard_Integer n, const char** a)
375 if (n <= 1) return 1;
376 for (Standard_Integer i = 1; i < n; i++) {
377 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
386 //=======================================================================
388 //=======================================================================
390 static Standard_Integer value(Draw_Interpretor& di, Standard_Integer n, const char** a)
392 if (n != 2) return 1;
393 di << Draw::Atof(a[1]);
398 //=======================================================================
401 //=======================================================================
402 static Standard_Integer dname(Draw_Interpretor& di, Standard_Integer n, const char** a)
408 Standard_PCharacter pC;
410 Handle(Draw_Drawable3D) aD;
412 for (i = 1; i < n; ++i) {
413 aD = Draw::Get(a[i]);
415 //modified by NIZNHY-PKV Tue Jun 10 10:18:13 2008f
417 pC=(Standard_PCharacter)aD->Name();
419 //modified by NIZNHY-PKV Tue Jun 10 10:18:18 2008t
425 //=======================================================================
427 //=======================================================================
430 static Standard_Integer dump(Draw_Interpretor& DI, Standard_Integer n, const char** a)
434 for (i = 1; i < n; i++) {
435 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
437 Standard_SStream sss;
439 sss << "\n\n*********** Dump of " << a[i] << " *************\n";
447 //=======================================================================
449 //=======================================================================
451 static Standard_Integer copy(Draw_Interpretor& , Standard_Integer n, const char** a)
454 Standard_Boolean cop = !strcasecmp(a[0],"copy");
456 Handle(Draw_Drawable3D) D;
457 for (Standard_Integer i = 1; i < n; i += 2) {
458 if (i+1 >= n) return 0;
465 Draw::Set(a[i],Handle(Draw_Drawable3D)());
473 //=======================================================================
476 //=======================================================================
478 static Standard_Integer repaintall(Draw_Interpretor& , Standard_Integer , const char** )
480 if (repaint2d) dout.Repaint2D();
481 repaint2d = Standard_False;
482 if (repaint3d) dout.Repaint3D();
483 repaint3d = Standard_False;
488 //=======================================================================
491 //=======================================================================
493 static Standard_Integer set(Draw_Interpretor& di, Standard_Integer n, const char** a)
496 Standard_Integer i = 1;
498 for (i = 1; i < n; i += 2) {
500 if (i+1 < n) val = Draw::Atof(a[i+1]);
507 //=======================================================================
510 //=======================================================================
512 static Standard_Integer dsetenv(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
515 Message::SendFail() << "Use: " << argv[0] << " {varname} [value]";
519 OSD_Environment env (argv[1]);
520 if (argc > 2 && argv[2][0] != '\0')
522 env.SetValue (argv[2]);
530 //=======================================================================
533 //=======================================================================
535 static Standard_Integer dgetenv(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
538 Message::SendFail() << "Use: " << argv[0] << " {varname}";
542 const char* val = getenv (argv[1]);
543 di << ( val ? val : "" );
547 //=======================================================================
550 //=======================================================================
552 static Standard_Integer isdraw(Draw_Interpretor& di, Standard_Integer n, const char** a)
554 if (n != 2) return 1;
555 Handle(Draw_Drawable3D) D = Draw::Get (a[1]);
563 //=======================================================================
566 //=======================================================================
568 Standard_Integer isprot(Draw_Interpretor& di, Standard_Integer n, const char** a)
570 if (n != 2) return 1;
571 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
584 //=======================================================================
587 //=======================================================================
589 static Standard_Integer pick(Draw_Interpretor& , Standard_Integer n, const char** a)
593 Standard_Integer X,Y,b;
594 Standard_Boolean wait = (n == 6);
595 if (!wait) id = Draw::Atoi(a[1]);
596 dout.Select(id,X,Y,b,wait);
597 Standard_Real z = dout.Zoom(id);
598 gp_Pnt P((Standard_Real)X /z,(Standard_Real)Y /z,0);
604 Draw::Set(a[2],P.X());
605 Draw::Set(a[3],P.Y());
606 Draw::Set(a[4],P.Z());
612 //=======================================================================
615 //=======================================================================
617 static Standard_Integer lastrep(Draw_Interpretor& di, Standard_Integer n, const char** a)
621 Draw::Set(a[1],p_id);
627 Standard_Real z = dout.Zoom(p_id);
628 gp_Pnt P((Standard_Real)p_X /z,(Standard_Real)p_Y /z,0);
630 dout.GetTrsf(p_id,T);
633 Draw::Set(a[2],P.X());
634 Draw::Set(a[3],P.Y());
635 Draw::Set(a[4],P.Z());
638 di << "Too many args";
641 Draw::Set(a[n-1],p_b);
647 //=======================================================================
650 //=======================================================================
651 void Draw::Set(const Standard_CString name,
652 const Handle(Draw_Drawable3D)& D)
654 Draw::Set(name,D,autodisp);
658 static char* tracevar(ClientData CD, Tcl_Interp*,const char* name,const char*, int)
660 // protect if the map was destroyed before the interpretor
661 if (Draw::Drawables().IsEmpty())
666 Draw_Interpretor& aCommands = Draw::GetInterpretor();
668 // MSV 9.10.14 CR25344
669 Handle(Draw_Drawable3D) D(reinterpret_cast<Draw_Drawable3D*>(CD));
671 Tcl_UntraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
675 if (D->Protected()) {
676 D->Name(Tcl_SetVar(aCommands.Interp(),name,name,0));
677 return (char*) "variable is protected";
680 dout.RemoveDrawable(D);
682 repaint3d = Standard_True;
684 repaint2d = Standard_True;
686 Tcl_UntraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
688 Draw_changeDrawables().Remove(D);
693 //=======================================================================
696 //=======================================================================
697 void Draw::Set(const Standard_CString name,
698 const Handle(Draw_Drawable3D)& D,
699 const Standard_Boolean displ)
701 Draw_Interpretor& aCommands = Draw::GetInterpretor();
703 if ((name[0] == '.') && (name[1] == '\0')) {
705 dout.RemoveDrawable(D);
706 if (displ) dout << D;
710 // Check if the variable with the same name exists
712 Tcl_VarTraceInfo(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
714 Handle(Draw_Drawable3D) anOldD(reinterpret_cast<Draw_Drawable3D*>(aCD));
715 if (!anOldD.IsNull()) {
716 if (Draw::Drawables().Contains(anOldD) && anOldD->Protected()) {
717 std::cout << "variable is protected" << std::endl;
723 Tcl_UnsetVar(aCommands.Interp(),name,0);
726 Draw_changeDrawables().Add(D);
727 D->Name(Tcl_SetVar(aCommands.Interp(),name,name,0));
729 // set the trace function
730 Tcl_TraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
731 tracevar,reinterpret_cast<ClientData>(D.operator->()));
736 else if (D->Visible())
737 dout.RemoveDrawable(D);
741 //=======================================================================
744 //=======================================================================
745 void Draw::Set(const Standard_CString theName, const Standard_Real theValue)
747 if (Handle(Draw_Number) aNumber = Handle(Draw_Number)::DownCast (Draw::GetExisting (theName)))
749 aNumber->Value (theValue);
753 aNumber = new Draw_Number (theValue);
754 Draw::Set (theName, aNumber, Standard_False);
758 //=======================================================================
759 //function : getDrawable
761 //=======================================================================
762 Handle(Draw_Drawable3D) Draw::getDrawable (Standard_CString& theName,
763 Standard_Boolean theToAllowPick)
765 const Standard_Boolean toPick = ((theName[0] == '.') && (theName[1] == '\0'));
768 ClientData aCD = Tcl_VarTraceInfo (Draw::GetInterpretor().Interp(), theName, TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar, NULL);
769 Handle(Draw_Drawable3D) aDrawable = reinterpret_cast<Draw_Drawable3D*>(aCD);
770 return Draw::Drawables().Contains (aDrawable)
772 : Handle(Draw_Drawable3D)();
774 else if (!theToAllowPick)
776 return Handle(Draw_Drawable3D)();
779 std::cout << "Pick an object" << std::endl;
780 Handle(Draw_Drawable3D) aDrawable;
781 dout.Select (p_id, p_X, p_Y, p_b);
782 dout.Pick (p_id, p_X, p_Y, 5, aDrawable, 0);
783 if (!aDrawable.IsNull()
784 && aDrawable->Name() != NULL)
786 theName = p_Name = aDrawable->Name();
791 //=======================================================================
794 //=======================================================================
795 Standard_Boolean Draw::Get (const Standard_CString theName,
796 Standard_Real& theValue)
798 if (Handle(Draw_Number) aNumber = Handle(Draw_Number)::DownCast (Draw::GetExisting (theName)))
800 theValue = aNumber->Value();
801 return Standard_True;
803 return Standard_False;
806 //=======================================================================
807 //function : LastPick
809 //=======================================================================
810 void Draw::LastPick(Standard_Integer& view,
813 Standard_Integer& button)
820 //=======================================================================
823 //=======================================================================
826 repaint2d = Standard_True;
827 repaint3d = Standard_True;
830 //=======================================================================
831 //function : trigonometric functions
833 //=======================================================================
835 //static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer n, const char** a)
836 static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer , const char** a)
839 Standard_Real x = Draw::Atof(a[1]);
841 if (!strcasecmp(a[0],"cos"))
843 else if (!strcasecmp(a[0],"sin"))
845 else if (!strcasecmp(a[0],"tan"))
847 else if (!strcasecmp(a[0],"sqrt"))
849 else if (!strcasecmp(a[0],"acos"))
851 else if (!strcasecmp(a[0],"asin"))
853 else if (!strcasecmp(a[0],"atan2"))
854 di << ATan2(x,Draw::Atof(a[2]));
860 //=======================================================================
862 //=======================================================================
864 static Standard_Boolean Numeric(char c)
866 return (c == '.' || (c >= '0' && c <= '9'));
869 static Standard_Boolean Alphabetic(char c)
871 return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '_'));
874 static Standard_Real Parse(char*&);
876 static Standard_Real ParseValue (char*& theName)
878 while (*theName == ' ' || *theName == '\t') { ++theName; }
892 std::cout << "Mismatched parenthesis" << std::endl;
900 x = ParseValue (theName);
906 x = - ParseValue (theName);
913 while (Numeric (*p)) { ++p; }
914 // process scientific notation
915 if ((*p == 'e') || (*p == 'E'))
917 if (Numeric (*(p+1)) || *(p+1) == '+' || *(p+1) == '-')
922 while (Numeric (*p) || Alphabetic (*p)) { p++; }
926 if (Numeric (*theName)) // numeric literal
930 else if (!Draw::Get ((Standard_CString )theName, x)) // variable
932 // search for a function ...
935 Standard_Integer argc = 1;
937 while ((*q == ' ') || (*q == '\t')) { ++q; }
940 Standard_Integer pc = 1;
943 while ((pc > 0) && *q)
945 if (*q == '(') { ++pc; }
946 if (*q == ')') { --pc; }
947 if ((pc == 1) && (*q == ',')) { ++argc; }
952 std::cout << "Unclosed parenthesis"<< std::endl;
957 // build function call
958 // replace , and first and last () by space
961 Standard_Integer i = 2;
962 while (*p != '(') { ++p; }
968 if (*p == '(') { ++pc; }
969 if (*p == ')') { --pc; }
970 if ((pc == 1) && (*p == ','))
984 Draw_Interpretor& aCommands = Draw::GetInterpretor();
986 // call the function, save the current result
987 TCollection_AsciiString sv (aCommands.Result());
988 if (*aCommands.Result())
992 if (aCommands.Eval (theName) != 0)
994 std::cout << "Call of function " << theName << " failed" << std::endl;
999 x = Atof (aCommands.Result());
1011 Draw_ParseFailed = Standard_True;
1020 while (*theName == ' ' || *theName == '\t')
1028 static Standard_Real ParseFactor(char*& name)
1030 Standard_Real x = ParseValue(name);
1034 if (c == '\0') return x;
1039 x *= ParseValue(name);
1043 x /= ParseValue(name);
1054 static Standard_Real Parse(char*& name)
1056 Standard_Real x = ParseFactor(name);
1060 if (c == '\0') return x;
1065 x += ParseFactor(name);
1069 x -= ParseFactor(name);
1080 //=======================================================================
1083 //=======================================================================
1084 Standard_Real Draw::Atof(const Standard_CString theName)
1087 NCollection_Array1<char> aBuff (0, (Standard_Integer )strlen (theName));
1088 char* n = &aBuff.ChangeFirst();
1089 strcpy (n, theName);
1090 Draw_ParseFailed = Standard_False;
1091 Standard_Real x = Parse(n);
1092 while ((*n == ' ') || (*n == '\t')) n++;
1093 if (*n) Draw_ParseFailed = Standard_True;
1097 //=======================================================================
1098 // function : ParseReal
1100 //=======================================================================
1101 bool Draw::ParseReal (const Standard_CString theExpressionString, Standard_Real& theParsedRealValue)
1103 const Standard_Real aParsedRealValue = Atof (theExpressionString);
1104 if (Draw_ParseFailed)
1106 Draw_ParseFailed = Standard_False;
1109 theParsedRealValue = aParsedRealValue;
1113 //=======================================================================
1116 //=======================================================================
1117 Standard_Integer Draw::Atoi(const Standard_CString name)
1119 return (Standard_Integer) Draw::Atof(name);
1122 //=======================================================================
1123 // function : ParseInteger
1125 //=======================================================================
1126 bool Draw::ParseInteger (const Standard_CString theExpressionString, Standard_Integer& theParsedIntegerValue)
1128 Standard_Real aParsedRealValue = 0.0;
1129 if (!ParseReal (theExpressionString, aParsedRealValue))
1133 const Standard_Integer aParsedIntegerValue = static_cast<Standard_Integer> (aParsedRealValue);
1134 if (static_cast<Standard_Real> (aParsedIntegerValue) != aParsedRealValue)
1138 theParsedIntegerValue = aParsedIntegerValue;
1142 //=======================================================================
1144 //purpose : set a TCL var
1145 //=======================================================================
1146 void Draw::Set(const Standard_CString Name, const Standard_CString val)
1148 Standard_PCharacter pName, pVal;
1150 pName=(Standard_PCharacter)Name;
1151 pVal=(Standard_PCharacter)val;
1153 Tcl_SetVar(Draw::GetInterpretor().Interp(), pName, pVal, 0);
1156 //=======================================================================
1157 //function : Drawables
1159 //=======================================================================
1160 const NCollection_Map<Handle(Draw_Drawable3D)>& Draw::Drawables()
1162 return Draw_changeDrawables();
1165 //=======================================================================
1166 // Command management
1167 // refresh the screen
1168 //=======================================================================
1170 static void before()
1172 repaint2d = Standard_False;
1173 repaint3d = Standard_False;
1176 void Draw_RepaintNowIfNecessary()
1178 if (repaint2d) dout.Repaint2D();
1179 if (repaint3d) dout.Repaint3D();
1180 repaint2d = Standard_False;
1181 repaint3d = Standard_False;
1184 static void after(Standard_Integer)
1186 Draw_RepaintNowIfNecessary();
1189 extern void (*Draw_BeforeCommand)();
1190 extern void (*Draw_AfterCommand)(Standard_Integer);
1193 //=======================================================================
1194 //function : Commands
1196 //=======================================================================
1197 void Draw::VariableCommands(Draw_Interpretor& theCommandsArg)
1199 static Standard_Boolean Done = Standard_False;
1201 Done = Standard_True;
1203 // set up start and stop command
1204 Draw_BeforeCommand = &before;
1205 Draw_AfterCommand = &after;
1207 // Register save/restore tools
1208 Draw_Number::RegisterFactory();
1210 // set up some variables
1212 Handle(Draw_Axis3D) theAxes3d = new Draw_Axis3D(gp_Pnt(0,0,0),Draw_bleu,20);
1214 Draw::Set(n,theAxes3d);
1215 theAxes3d->Protected(Standard_True);
1217 Handle(Draw_Axis2D) theAxes2d = new Draw_Axis2D(gp_Pnt2d(0,0),Draw_bleu,20);
1219 Draw::Set(n,theAxes2d);
1220 theAxes2d->Protected(Standard_True);
1224 Draw::Get(n)->Protected(Standard_True);
1227 Draw::Set(n,RealLast());
1228 Draw::Get(n)->Protected(Standard_True);
1231 Draw::Set(n,RealFirst());
1232 Draw::Get(n)->Protected(Standard_True);
1235 Handle(Draw_Grid) theGrid = new Draw_Grid();
1236 Draw::Set(n, theGrid);
1237 theGrid->Protected(Standard_True);
1242 g = "DRAW Numeric functions";
1244 theCommandsArg.Add("cos" ,"cos(x)" ,__FILE__,trigo,g);
1245 theCommandsArg.Add("sin" ,"sin(x)" ,__FILE__,trigo,g);
1246 theCommandsArg.Add("tan" ,"tan(x)" ,__FILE__,trigo,g);
1247 theCommandsArg.Add("acos" ,"acos(x)" ,__FILE__,trigo,g);
1248 theCommandsArg.Add("asin" ,"asin(x)" ,__FILE__,trigo,g);
1249 theCommandsArg.Add("atan2" ,"atan2(x,y)" ,__FILE__,trigo,g);
1250 theCommandsArg.Add("sqrt","sqrt(x)",__FILE__,trigo,g);
1252 g = "DRAW Variables management";
1254 theCommandsArg.Add("protect","protect name ...",__FILE__,protect,g);
1255 theCommandsArg.Add("unprotect","unprotect name ...",__FILE__,protect,g);
1257 theCommandsArg.Add("bsave","bsave name filename",__FILE__,save,g);
1258 theCommandsArg.Add("brestore","brestore filename name",__FILE__,restore,g);
1260 theCommandsArg.Add("isdraw","isdraw var, return 1 if Draw value",__FILE__,isdraw,g);
1261 theCommandsArg.Add("isprot","isprot var, return 1 if Draw var is protected",__FILE__,isprot,g);
1263 theCommandsArg.Add("autodisplay","toggle autodisplay [0/1]",__FILE__,autodisplay,g);
1264 theCommandsArg.Add("display","display [name1 name2 ...], no names display all",__FILE__,display,g);
1265 theCommandsArg.Add("donly","donly [name1 name2 ...], erase and display",__FILE__,erase,g);
1266 theCommandsArg.Add("erase","erase [name1 name2 ...], no names erase all",__FILE__,erase,g);
1267 theCommandsArg.Add("draw","draw view mode [name1 name2 ...], draw on view with mode",__FILE__,draw,g);
1268 theCommandsArg.Add("clear","clear display",__FILE__,erase,g);
1269 theCommandsArg.Add("2dclear","clear display (2d objects)",__FILE__,erase,g);
1270 theCommandsArg.Add("repaint","repaint, force redraw",__FILE__,repaintall,g);
1272 theCommandsArg.Add("dtyp", "dtyp name1 name2",__FILE__,whatis,g);
1273 theCommandsArg.Add("dval", "dval name, return value",__FILE__,value,g);
1274 theCommandsArg.Add("dname", "dname name, print name",__FILE__,dname,g);
1275 theCommandsArg.Add("dump", "dump name1 name2 ...",__FILE__,dump,g);
1276 theCommandsArg.Add("copy", "copy name1 toname1 name2 toname2 ...",__FILE__,copy,g);
1277 // san - 02/08/2002 - `rename` command changed to `renamevar` since it conflicts with
1278 // the built-in Tcl command `rename`
1279 //theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,copy,g);
1280 theCommandsArg.Add("renamevar","renamevar name1 toname1 name2 toname2 ...",__FILE__,copy,g);
1281 theCommandsArg.Add("dset","var1 value1 vr2 value2 ...",__FILE__,set,g);
1283 // commands to access C environment variables; see Mantis issue #23197
1284 theCommandsArg.Add("dgetenv","var : get value of environment variable in C subsystem",__FILE__,dgetenv,g);
1285 theCommandsArg.Add("dsetenv","var [value] : set (unset if value is empty) environment variable in C subsystem",__FILE__,dsetenv,g);
1287 theCommandsArg.Add("pick","pick id X Y Z b [nowait]",__FILE__,pick,g);
1288 theCommandsArg.Add("lastrep","lastrep id X Y [Z] b, return name",__FILE__,lastrep,g);