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_OpenFile.hxx>
46 Standard_Boolean Draw_ParseFailed = Standard_True;
48 static Standard_Boolean autodisp = Standard_True;
49 static Standard_Boolean repaint2d = Standard_False, repaint3d = Standard_False;
51 //! Returns dictionary of variables
52 //! Variables are stored in a map Integer, Transient.
53 //! The Integer Value is the content of the Tcl variable.
54 static NCollection_Map<Handle(Draw_Drawable3D)>& Draw_changeDrawables()
56 static NCollection_Map<Handle(Draw_Drawable3D)> theVariables;
60 //=======================================================================
61 //function : FindVariable
63 //=======================================================================
65 static Standard_Integer p_id = 0;
66 static Standard_Integer p_X = 0;
67 static Standard_Integer p_Y = 0;
68 static Standard_Integer p_b = 0;
69 static const char* p_Name = "";
71 //=======================================================================
73 //=======================================================================
74 static Standard_Integer save (Draw_Interpretor& theDI,
75 Standard_Integer theNbArgs,
76 const char** theArgVec)
80 theDI << "Syntax error: wrong number of arguments!\n";
81 theDI.PrintHelp (theArgVec[0]);
85 Handle(Draw_Drawable3D) aDrawable = Draw::Get (theArgVec[1]);
86 if (aDrawable.IsNull())
88 theDI << "Syntax error: '" << theArgVec[1] << "' is not a drawable";
92 const char* aName = theArgVec[2];
93 std::ofstream aStream;
94 aStream.precision (15);
95 OSD_OpenStream (aStream, aName, std::ios::out);
96 if (!aStream.is_open() || !aStream.good())
98 theDI << "Error: cannot open file for writing " << aName;
104 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
105 Standard_CString aToolTypeName = aDrawable->DynamicType()->Name();
106 aStream << aToolTypeName << "\n";
107 Draw::SetProgressBar (aProgress);
108 aDrawable->Save (aStream);
110 catch (const Standard_NotImplemented& )
112 theDI << "Error: no method for saving " << theArgVec[1];
117 Draw::SetProgressBar (Handle(Draw_ProgressIndicator)());
120 const Standard_Boolean aRes = aStream.good() && !errno;
123 theDI << "Error: file has not been written";
127 theDI << theArgVec[1];
131 //=======================================================================
133 //=======================================================================
134 static Standard_Integer restore (Draw_Interpretor& theDI,
135 Standard_Integer theNbArgs,
136 const char** theArgVec)
143 const char* aFileName = theArgVec[1];
144 const char* aVarName = theArgVec[2];
146 std::filebuf aFileBuf;
147 std::istream aStream (&aFileBuf);
148 OSD_OpenStream (aFileBuf, aFileName, std::ios::in);
149 if (!aFileBuf.is_open())
151 theDI << "Error: cannot open file for reading: '" << aFileName << "'";
155 char aType[255] = {};
159 theDI << "Error: cannot read file: '" << aFileName << "'";
164 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
165 Draw::SetProgressBar (aProgress);
166 Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, aStream);
167 if (aDrawable.IsNull())
169 // assume that this file stores a DBRep_DrawableShape variable
170 aStream.seekg (0, std::ios::beg);
171 aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", aStream);
173 if (aDrawable.IsNull())
175 theDI << "Error: cannot restore a " << aType;
179 Draw::Set (aVarName, aDrawable, aDrawable->IsDisplayable() && autodisp);
180 Draw::SetProgressBar (Handle(Draw_ProgressIndicator)());
187 //=======================================================================
189 //=======================================================================
191 static Standard_Integer display(Draw_Interpretor& di, Standard_Integer n, const char** a)
193 if (n <= 1) return 1;
195 for (Standard_Integer i = 1; i < n; i++) {
196 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
208 //=======================================================================
209 // erase, clear, donly
210 //=======================================================================
212 static Standard_Integer erase(Draw_Interpretor& di, Standard_Integer n, const char** a)
214 static Standard_Boolean draw_erase_mute = Standard_False;
216 if (!strcasecmp(a[1],"-mute")) {
217 draw_erase_mute = Standard_True;
222 Standard_Boolean donly = !strcasecmp(a[0],"donly");
224 if (n <= 1 || donly) {
225 // clear, 2dclear, donly, erase (without arguments)
228 // solve the names for "." before erasing
230 for (i = 1; i < n; i++) {
231 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
233 if ((a[i][0] == '.') && (a[i][1] == '\0'))
234 std::cout << "Missed !!!" << std::endl;
240 // sauvegarde des proteges visibles
241 Draw_SequenceOfDrawable3D prot;
242 for (NCollection_Map<Handle(Draw_Drawable3D)>::Iterator aMapIt (Draw::Drawables()); aMapIt.More(); aMapIt.Next())
244 const Handle(Draw_Drawable3D)& D = aMapIt.Key();
247 if (D->Protected() && D->Visible())
254 // effacement de toutes les variables
255 Standard_Integer erasemode = 1;
256 if (a[0][0] == '2') erasemode = 2;
257 if (a[0][0] == 'c') erasemode = 3;
259 // effacement des graphiques non variables
262 else if (erasemode == 3)
267 // affichage pour donly
269 for (i = 1; i < n; i++) {
270 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
274 if (!draw_erase_mute) di << a[i] << " ";
280 // afficahge des proteges
281 for (i = 1; i <= prot.Length(); i++)
287 for (Standard_Integer i = 1; i < n; i++) {
288 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
291 dout.RemoveDrawable(D);
292 if (!draw_erase_mute) di << D->Name() << " ";
299 draw_erase_mute = Standard_False;
300 repaint2d = Standard_False;
301 repaint3d = Standard_False;
308 //=======================================================================
310 //=======================================================================
312 static Standard_Integer draw(Draw_Interpretor& , Standard_Integer n, const char** a)
315 Standard_Integer id = Draw::Atoi(a[1]);
316 if (!dout.HasView(id)) {
317 Message::SendFail() << "bad view number in draw";
320 Standard_Integer mo = Draw::Atoi(a[2]);
321 Draw_Display d = dout.MakeDisplay(id);
324 for (i = 3; i < n; i++) {
325 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
326 if (!D.IsNull()) D->DrawOn(d);
332 //=======================================================================
333 // protect, unprotect
334 //=======================================================================
336 static Standard_Integer protect(Draw_Interpretor& di, Standard_Integer n, const char** a)
338 if (n <= 1) return 1;
339 Standard_Boolean prot = *a[0] != 'u';
340 for (Standard_Integer i = 1; i < n; i++) {
341 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
350 //=======================================================================
352 //=======================================================================
354 static Standard_Integer autodisplay(Draw_Interpretor& di, Standard_Integer n, const char** a)
357 autodisp = !autodisp;
359 autodisp = !(!strcasecmp(a[1],"0"));
370 //=======================================================================
372 //=======================================================================
374 static Standard_Integer whatis(Draw_Interpretor& di, Standard_Integer n, const char** a)
376 if (n <= 1) return 1;
377 for (Standard_Integer i = 1; i < n; i++) {
378 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
387 //=======================================================================
389 //=======================================================================
391 static Standard_Integer value(Draw_Interpretor& di, Standard_Integer n, const char** a)
393 if (n != 2) return 1;
394 di << Draw::Atof(a[1]);
399 //=======================================================================
402 //=======================================================================
403 static Standard_Integer dname(Draw_Interpretor& di, Standard_Integer n, const char** a)
409 Standard_PCharacter pC;
411 Handle(Draw_Drawable3D) aD;
413 for (i = 1; i < n; ++i) {
414 aD = Draw::Get(a[i]);
416 //modified by NIZNHY-PKV Tue Jun 10 10:18:13 2008f
418 pC=(Standard_PCharacter)aD->Name();
420 //modified by NIZNHY-PKV Tue Jun 10 10:18:18 2008t
426 //=======================================================================
428 //=======================================================================
431 static Standard_Integer dump(Draw_Interpretor& DI, Standard_Integer n, const char** a)
435 for (i = 1; i < n; i++) {
436 Handle(Draw_Drawable3D) D = Draw::Get(a[i]);
438 Standard_SStream sss;
440 sss << "\n\n*********** Dump of " << a[i] << " *************\n";
448 //=======================================================================
450 //=======================================================================
452 static Standard_Integer copy(Draw_Interpretor& , Standard_Integer n, const char** a)
455 Standard_Boolean cop = !strcasecmp(a[0],"copy");
457 Handle(Draw_Drawable3D) D;
458 for (Standard_Integer i = 1; i < n; i += 2) {
459 if (i+1 >= n) return 0;
466 Draw::Set(a[i],Handle(Draw_Drawable3D)());
474 //=======================================================================
477 //=======================================================================
479 static Standard_Integer repaintall(Draw_Interpretor& , Standard_Integer , const char** )
481 if (repaint2d) dout.Repaint2D();
482 repaint2d = Standard_False;
483 if (repaint3d) dout.Repaint3D();
484 repaint3d = Standard_False;
489 //=======================================================================
492 //=======================================================================
494 static Standard_Integer set(Draw_Interpretor& di, Standard_Integer n, const char** a)
497 Standard_Integer i = 1;
499 for (i = 1; i < n; i += 2) {
501 if (i+1 < n) val = Draw::Atof(a[i+1]);
508 //=======================================================================
511 //=======================================================================
513 static Standard_Integer dsetenv(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
516 Message::SendFail() << "Use: " << argv[0] << " {varname} [value]";
520 OSD_Environment env (argv[1]);
521 if (argc > 2 && argv[2][0] != '\0')
523 env.SetValue (argv[2]);
531 //=======================================================================
534 //=======================================================================
536 static Standard_Integer dgetenv(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
539 Message::SendFail() << "Use: " << argv[0] << " {varname}";
543 const char* val = getenv (argv[1]);
544 di << ( val ? val : "" );
548 //=======================================================================
551 //=======================================================================
553 static Standard_Integer isdraw(Draw_Interpretor& di, Standard_Integer n, const char** a)
555 if (n != 2) return 1;
556 Handle(Draw_Drawable3D) D = Draw::Get (a[1]);
564 //=======================================================================
567 //=======================================================================
569 Standard_Integer isprot(Draw_Interpretor& di, Standard_Integer n, const char** a)
571 if (n != 2) return 1;
572 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
585 //=======================================================================
588 //=======================================================================
590 static Standard_Integer pick(Draw_Interpretor& , Standard_Integer n, const char** a)
594 Standard_Integer X,Y,b;
595 Standard_Boolean wait = (n == 6);
596 if (!wait) id = Draw::Atoi(a[1]);
597 dout.Select(id,X,Y,b,wait);
598 Standard_Real z = dout.Zoom(id);
599 gp_Pnt P((Standard_Real)X /z,(Standard_Real)Y /z,0);
605 Draw::Set(a[2],P.X());
606 Draw::Set(a[3],P.Y());
607 Draw::Set(a[4],P.Z());
613 //=======================================================================
616 //=======================================================================
618 static Standard_Integer lastrep(Draw_Interpretor& di, Standard_Integer n, const char** a)
622 Draw::Set(a[1],p_id);
628 Standard_Real z = dout.Zoom(p_id);
629 gp_Pnt P((Standard_Real)p_X /z,(Standard_Real)p_Y /z,0);
631 dout.GetTrsf(p_id,T);
634 Draw::Set(a[2],P.X());
635 Draw::Set(a[3],P.Y());
636 Draw::Set(a[4],P.Z());
639 di << "Too many args";
642 Draw::Set(a[n-1],p_b);
648 //=======================================================================
651 //=======================================================================
652 void Draw::Set(const Standard_CString name,
653 const Handle(Draw_Drawable3D)& D)
655 Draw::Set(name,D,autodisp);
659 static char* tracevar(ClientData CD, Tcl_Interp*,const char* name,const char*, int)
661 // protect if the map was destroyed before the interpretor
662 if (Draw::Drawables().IsEmpty())
667 Draw_Interpretor& aCommands = Draw::GetInterpretor();
669 // MSV 9.10.14 CR25344
670 Handle(Draw_Drawable3D) D(reinterpret_cast<Draw_Drawable3D*>(CD));
672 Tcl_UntraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
676 if (D->Protected()) {
677 D->Name(Tcl_SetVar(aCommands.Interp(),name,name,0));
678 return (char*) "variable is protected";
681 dout.RemoveDrawable(D);
683 repaint3d = Standard_True;
685 repaint2d = Standard_True;
687 Tcl_UntraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
689 Draw_changeDrawables().Remove(D);
694 //=======================================================================
697 //=======================================================================
698 void Draw::Set(const Standard_CString name,
699 const Handle(Draw_Drawable3D)& D,
700 const Standard_Boolean displ)
702 Draw_Interpretor& aCommands = Draw::GetInterpretor();
704 if ((name[0] == '.') && (name[1] == '\0')) {
706 dout.RemoveDrawable(D);
707 if (displ) dout << D;
711 // Check if the variable with the same name exists
713 Tcl_VarTraceInfo(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
715 Handle(Draw_Drawable3D) anOldD(reinterpret_cast<Draw_Drawable3D*>(aCD));
716 if (!anOldD.IsNull()) {
717 if (Draw::Drawables().Contains(anOldD) && anOldD->Protected()) {
718 std::cout << "variable is protected" << std::endl;
724 Tcl_UnsetVar(aCommands.Interp(),name,0);
727 Draw_changeDrawables().Add(D);
728 D->Name(Tcl_SetVar(aCommands.Interp(),name,name,0));
730 // set the trace function
731 Tcl_TraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
732 tracevar,reinterpret_cast<ClientData>(D.operator->()));
737 else if (D->Visible())
738 dout.RemoveDrawable(D);
742 //=======================================================================
745 //=======================================================================
746 void Draw::Set(const Standard_CString theName, const Standard_Real theValue)
748 if (Handle(Draw_Number) aNumber = Handle(Draw_Number)::DownCast (Draw::GetExisting (theName)))
750 aNumber->Value (theValue);
754 aNumber = new Draw_Number (theValue);
755 Draw::Set (theName, aNumber, Standard_False);
759 //=======================================================================
760 //function : getDrawable
762 //=======================================================================
763 Handle(Draw_Drawable3D) Draw::getDrawable (Standard_CString& theName,
764 Standard_Boolean theToAllowPick)
766 const Standard_Boolean toPick = ((theName[0] == '.') && (theName[1] == '\0'));
769 ClientData aCD = Tcl_VarTraceInfo (Draw::GetInterpretor().Interp(), theName, TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar, NULL);
770 Handle(Draw_Drawable3D) aDrawable = reinterpret_cast<Draw_Drawable3D*>(aCD);
771 return Draw::Drawables().Contains (aDrawable)
773 : Handle(Draw_Drawable3D)();
775 else if (!theToAllowPick)
777 return Handle(Draw_Drawable3D)();
780 std::cout << "Pick an object" << std::endl;
781 Handle(Draw_Drawable3D) aDrawable;
782 dout.Select (p_id, p_X, p_Y, p_b);
783 dout.Pick (p_id, p_X, p_Y, 5, aDrawable, 0);
784 if (!aDrawable.IsNull()
785 && aDrawable->Name() != NULL)
787 theName = p_Name = aDrawable->Name();
792 //=======================================================================
795 //=======================================================================
796 Standard_Boolean Draw::Get (const Standard_CString theName,
797 Standard_Real& theValue)
799 if (Handle(Draw_Number) aNumber = Handle(Draw_Number)::DownCast (Draw::GetExisting (theName)))
801 theValue = aNumber->Value();
802 return Standard_True;
804 return Standard_False;
807 //=======================================================================
808 //function : LastPick
810 //=======================================================================
811 void Draw::LastPick(Standard_Integer& view,
814 Standard_Integer& button)
821 //=======================================================================
824 //=======================================================================
827 repaint2d = Standard_True;
828 repaint3d = Standard_True;
831 //=======================================================================
832 //function : trigonometric functions
834 //=======================================================================
836 //static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer n, const char** a)
837 static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer , const char** a)
840 Standard_Real x = Draw::Atof(a[1]);
842 if (!strcasecmp(a[0],"cos"))
844 else if (!strcasecmp(a[0],"sin"))
846 else if (!strcasecmp(a[0],"tan"))
848 else if (!strcasecmp(a[0],"sqrt"))
850 else if (!strcasecmp(a[0],"acos"))
852 else if (!strcasecmp(a[0],"asin"))
854 else if (!strcasecmp(a[0],"atan2"))
855 di << ATan2(x,Draw::Atof(a[2]));
861 //=======================================================================
863 //=======================================================================
865 static Standard_Boolean Numeric(char c)
867 return (c == '.' || (c >= '0' && c <= '9'));
870 static Standard_Boolean Alphabetic(char c)
872 return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '_'));
875 static Standard_Real Parse(char*&);
877 static Standard_Real ParseValue (char*& theName)
879 while (*theName == ' ' || *theName == '\t') { ++theName; }
893 std::cout << "Mismatched parenthesis" << std::endl;
901 x = ParseValue (theName);
907 x = - ParseValue (theName);
914 while (Numeric (*p)) { ++p; }
915 // process scientific notation
916 if ((*p == 'e') || (*p == 'E'))
918 if (Numeric (*(p+1)) || *(p+1) == '+' || *(p+1) == '-')
923 while (Numeric (*p) || Alphabetic (*p)) { p++; }
927 if (Numeric (*theName)) // numeric literal
931 else if (!Draw::Get ((Standard_CString )theName, x)) // variable
933 // search for a function ...
936 Standard_Integer argc = 1;
938 while ((*q == ' ') || (*q == '\t')) { ++q; }
941 Standard_Integer pc = 1;
944 while ((pc > 0) && *q)
946 if (*q == '(') { ++pc; }
947 if (*q == ')') { --pc; }
948 if ((pc == 1) && (*q == ',')) { ++argc; }
953 std::cout << "Unclosed parenthesis"<< std::endl;
958 // build function call
959 // replace , and first and last () by space
962 Standard_Integer i = 2;
963 while (*p != '(') { ++p; }
969 if (*p == '(') { ++pc; }
970 if (*p == ')') { --pc; }
971 if ((pc == 1) && (*p == ','))
985 Draw_Interpretor& aCommands = Draw::GetInterpretor();
987 // call the function, save the current result
988 TCollection_AsciiString sv (aCommands.Result());
989 if (*aCommands.Result())
993 if (aCommands.Eval (theName) != 0)
995 std::cout << "Call of function " << theName << " failed" << std::endl;
1000 x = Atof (aCommands.Result());
1012 Draw_ParseFailed = Standard_True;
1021 while (*theName == ' ' || *theName == '\t')
1029 static Standard_Real ParseFactor(char*& name)
1031 Standard_Real x = ParseValue(name);
1035 if (c == '\0') return x;
1040 x *= ParseValue(name);
1044 x /= ParseValue(name);
1055 static Standard_Real Parse(char*& name)
1057 Standard_Real x = ParseFactor(name);
1061 if (c == '\0') return x;
1066 x += ParseFactor(name);
1070 x -= ParseFactor(name);
1081 //=======================================================================
1084 //=======================================================================
1085 Standard_Real Draw::Atof(const Standard_CString theName)
1088 NCollection_Array1<char> aBuff (0, (Standard_Integer )strlen (theName));
1089 char* n = &aBuff.ChangeFirst();
1090 strcpy (n, theName);
1091 Draw_ParseFailed = Standard_False;
1092 Standard_Real x = Parse(n);
1093 while ((*n == ' ') || (*n == '\t')) n++;
1094 if (*n) Draw_ParseFailed = Standard_True;
1098 //=======================================================================
1099 // function : ParseReal
1101 //=======================================================================
1102 bool Draw::ParseReal (const Standard_CString theExpressionString, Standard_Real& theParsedRealValue)
1104 const Standard_Real aParsedRealValue = Atof (theExpressionString);
1105 if (Draw_ParseFailed)
1107 Draw_ParseFailed = Standard_False;
1110 theParsedRealValue = aParsedRealValue;
1114 //=======================================================================
1117 //=======================================================================
1118 Standard_Integer Draw::Atoi(const Standard_CString name)
1120 return (Standard_Integer) Draw::Atof(name);
1123 //=======================================================================
1124 // function : ParseInteger
1126 //=======================================================================
1127 bool Draw::ParseInteger (const Standard_CString theExpressionString, Standard_Integer& theParsedIntegerValue)
1129 Standard_Real aParsedRealValue = 0.0;
1130 if (!ParseReal (theExpressionString, aParsedRealValue))
1134 const Standard_Integer aParsedIntegerValue = static_cast<Standard_Integer> (aParsedRealValue);
1135 if (static_cast<Standard_Real> (aParsedIntegerValue) != aParsedRealValue)
1139 theParsedIntegerValue = aParsedIntegerValue;
1143 //=======================================================================
1145 //purpose : set a TCL var
1146 //=======================================================================
1147 void Draw::Set(const Standard_CString Name, const Standard_CString val)
1149 Standard_PCharacter pName, pVal;
1151 pName=(Standard_PCharacter)Name;
1152 pVal=(Standard_PCharacter)val;
1154 Tcl_SetVar(Draw::GetInterpretor().Interp(), pName, pVal, 0);
1157 //=======================================================================
1158 //function : Drawables
1160 //=======================================================================
1161 const NCollection_Map<Handle(Draw_Drawable3D)>& Draw::Drawables()
1163 return Draw_changeDrawables();
1166 //=======================================================================
1167 // Command management
1168 // refresh the screen
1169 //=======================================================================
1171 static void before()
1173 repaint2d = Standard_False;
1174 repaint3d = Standard_False;
1177 void Draw_RepaintNowIfNecessary()
1179 if (repaint2d) dout.Repaint2D();
1180 if (repaint3d) dout.Repaint3D();
1181 repaint2d = Standard_False;
1182 repaint3d = Standard_False;
1185 static void after(Standard_Integer)
1187 Draw_RepaintNowIfNecessary();
1190 extern void (*Draw_BeforeCommand)();
1191 extern void (*Draw_AfterCommand)(Standard_Integer);
1194 //=======================================================================
1195 //function : Commands
1197 //=======================================================================
1198 void Draw::VariableCommands(Draw_Interpretor& theCommandsArg)
1200 static Standard_Boolean Done = Standard_False;
1202 Done = Standard_True;
1204 // set up start and stop command
1205 Draw_BeforeCommand = &before;
1206 Draw_AfterCommand = &after;
1208 // Register save/restore tools
1209 Draw_Number::RegisterFactory();
1211 // set up some variables
1213 Handle(Draw_Axis3D) theAxes3d = new Draw_Axis3D(gp_Pnt(0,0,0),Draw_bleu,20);
1215 Draw::Set(n,theAxes3d);
1216 theAxes3d->Protected(Standard_True);
1218 Handle(Draw_Axis2D) theAxes2d = new Draw_Axis2D(gp_Pnt2d(0,0),Draw_bleu,20);
1220 Draw::Set(n,theAxes2d);
1221 theAxes2d->Protected(Standard_True);
1225 Draw::Get(n)->Protected(Standard_True);
1228 Draw::Set(n,RealLast());
1229 Draw::Get(n)->Protected(Standard_True);
1232 Draw::Set(n,RealFirst());
1233 Draw::Get(n)->Protected(Standard_True);
1236 Handle(Draw_Grid) theGrid = new Draw_Grid();
1237 Draw::Set(n, theGrid);
1238 theGrid->Protected(Standard_True);
1243 g = "DRAW Numeric functions";
1245 theCommandsArg.Add("cos" ,"cos(x)" ,__FILE__,trigo,g);
1246 theCommandsArg.Add("sin" ,"sin(x)" ,__FILE__,trigo,g);
1247 theCommandsArg.Add("tan" ,"tan(x)" ,__FILE__,trigo,g);
1248 theCommandsArg.Add("acos" ,"acos(x)" ,__FILE__,trigo,g);
1249 theCommandsArg.Add("asin" ,"asin(x)" ,__FILE__,trigo,g);
1250 theCommandsArg.Add("atan2" ,"atan2(x,y)" ,__FILE__,trigo,g);
1251 theCommandsArg.Add("sqrt","sqrt(x)",__FILE__,trigo,g);
1253 g = "DRAW Variables management";
1255 theCommandsArg.Add("protect","protect name ...",__FILE__,protect,g);
1256 theCommandsArg.Add("unprotect","unprotect name ...",__FILE__,protect,g);
1258 theCommandsArg.Add("bsave","bsave name filename",__FILE__,save,g);
1259 theCommandsArg.Add("brestore","brestore filename name",__FILE__,restore,g);
1261 theCommandsArg.Add("isdraw","isdraw var, return 1 if Draw value",__FILE__,isdraw,g);
1262 theCommandsArg.Add("isprot","isprot var, return 1 if Draw var is protected",__FILE__,isprot,g);
1264 theCommandsArg.Add("autodisplay","toggle autodisplay [0/1]",__FILE__,autodisplay,g);
1265 theCommandsArg.Add("display","display [name1 name2 ...], no names display all",__FILE__,display,g);
1266 theCommandsArg.Add("donly","donly [name1 name2 ...], erase and display",__FILE__,erase,g);
1267 theCommandsArg.Add("erase","erase [name1 name2 ...], no names erase all",__FILE__,erase,g);
1268 theCommandsArg.Add("draw","draw view mode [name1 name2 ...], draw on view with mode",__FILE__,draw,g);
1269 theCommandsArg.Add("clear","clear display",__FILE__,erase,g);
1270 theCommandsArg.Add("2dclear","clear display (2d objects)",__FILE__,erase,g);
1271 theCommandsArg.Add("repaint","repaint, force redraw",__FILE__,repaintall,g);
1273 theCommandsArg.Add("dtyp", "dtyp name1 name2",__FILE__,whatis,g);
1274 theCommandsArg.Add("dval", "dval name, return value",__FILE__,value,g);
1275 theCommandsArg.Add("dname", "dname name, print name",__FILE__,dname,g);
1276 theCommandsArg.Add("dump", "dump name1 name2 ...",__FILE__,dump,g);
1277 theCommandsArg.Add("copy", "copy name1 toname1 name2 toname2 ...",__FILE__,copy,g);
1278 // san - 02/08/2002 - `rename` command changed to `renamevar` since it conflicts with
1279 // the built-in Tcl command `rename`
1280 //theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,copy,g);
1281 theCommandsArg.Add("renamevar","renamevar name1 toname1 name2 toname2 ...",__FILE__,copy,g);
1282 theCommandsArg.Add("dset","var1 value1 vr2 value2 ...",__FILE__,set,g);
1284 // commands to access C environment variables; see Mantis issue #23197
1285 theCommandsArg.Add("dgetenv","var : get value of environment variable in C subsystem",__FILE__,dgetenv,g);
1286 theCommandsArg.Add("dsetenv","var [value] : set (unset if value is empty) environment variable in C subsystem",__FILE__,dsetenv,g);
1288 theCommandsArg.Add("pick","pick id X Y Z b [nowait]",__FILE__,pick,g);
1289 theCommandsArg.Add("lastrep","lastrep id X Y [Z] b, return name",__FILE__,lastrep,g);