1 // Created on: 1996-10-21
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <TestTopOpe.ixx>
24 #include <Draw_Appli.hxx>
25 #include <Draw_Interpretor.hxx>
26 #include <TestTopOpeDraw_DrawableMesure.hxx>
27 #include <DrawTrSurf_Curve.hxx>
29 #include <TestTopOpeTools_Mesure.hxx>
30 #include <TestTopOpeTools_HArray1OfMesure.hxx>
31 #include <TestTopOpeDraw_Array1OfDrawableMesure.hxx>
32 #include <TColStd_Array1OfTransient.hxx>
33 #include <TColStd_Array1OfAsciiString.hxx>
36 Standard_IMPORT Draw_Viewer dout;
40 //static Standard_Boolean Bool;
41 static Standard_Integer NbMES = 0;
42 static TColStd_Array1OfAsciiString *PDel = NULL;
43 static TColStd_Array1OfAsciiString *PNAME = NULL;
44 static TestTopOpeTools_Array1OfMesure *PAMES = NULL;
46 //-----------------------------------------------
47 static Standard_Integer SetName(const Standard_Character *C, Draw_Interpretor& di)
48 //-----------------------------------------------
49 // here the number of measurement is managed
52 PNAME = new TColStd_Array1OfAsciiString(1, 100);
55 PDel = new TColStd_Array1OfAsciiString(1, 100);
57 if(NbMES >= 100) {di << "ATTENTION : last measurement accepted";}
58 for(Standard_Integer i = 1; i <= NbMES; i++) {
59 Standard_Character *Ch = (Standard_Character *)(*PNAME).Value(i).ToCString();
60 if( *Ch == *C) return i;
62 (*PNAME).SetValue(++NbMES, *C);
63 (*PDel).SetValue(NbMES, "0");
69 //-----------------------------------------------
70 static void SeemMesure(const Handle(TestTopOpeDraw_DrawableMesure) DM,const Standard_Integer CMES)
71 //-----------------------------------------------
73 char *pname = (char *)(*PNAME).Value(CMES).ToCString();
78 static void Mes_help(Draw_Interpretor& di)
81 di<<"mesure M : create/reset measurement M "<<"\n";
82 di<<"mesure reset : reinitialize all measurements"<<"\n";
83 di<<"mesure M n t : add data [n t] to M"<<"\n";
84 di<<"mesure range M : sort indexes 'min max' of M"<<"\n";
85 di<<"mesure minmax M : take 'xmin ymin xmax ymax' from M"<<"\n";
86 di<<"mesure xy <i> M : take 'x y' = M(i)"<<"\n";
87 di<<"seem M : visualize M"<<"\n";
88 di<<"seemx M fx : visualize M with factor in x"<<"\n";
89 di<<"seemx M fy : visualize M with factor in y"<<"\n";
90 di<<"seemxy M fx fy : visualize M with factor in x,y"<<"\n";
94 // ----------------------------------------------------------------------
95 Standard_Integer Mes(Draw_Interpretor& di,Standard_Integer na, const char** a)
96 // ----------------------------------------------------------------------
98 if (!strcmp(a[0],"mesure")) {
104 if (!strcmp(a[1],"reset")) { PAMES = NULL; return 0;}
106 Standard_Integer CurrentMES2 = SetName(a[1],di);
107 TestTopOpeTools_Mesure *MES2;
108 MES2 = new TestTopOpeTools_Mesure(a[1]);
109 if(PAMES == NULL) { PAMES = new TestTopOpeTools_Array1OfMesure(1, 100); }
110 (*PAMES).SetValue(CurrentMES2, *MES2);
114 if (!strcmp(a[1],"range")) {
115 const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[2],di));
118 else if (!strcmp(a[1],"minmax")) {
119 const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[2],di));
120 Standard_Integer n=M.NPnts();
121 Standard_Real xm=0,ym=0,xM=0,yM=0;
123 xm=1.e100;ym=1.e100;xM=-1.e100;yM=-1.e100;
124 for (Standard_Integer i=1;i<=n;i++) {
125 Standard_Real x,y,z;gp_Pnt p=M.Pnt(i);p.Coord(x,y,z);
126 xm=Min(xm,x);xM=Max(xM,x);
127 ym=Min(ym,y);yM=Max(yM,y);
130 di<<xm<<" "<<ym<<" "<<xM<<" "<<yM;
134 if (!strcmp(a[1],"xy")) {
135 Standard_Integer i = atoi(a[2]);
136 const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[3],di));
137 Standard_Real x,y,z;gp_Pnt p=M.Pnt(i);p.Coord(x,y,z);
141 Standard_Integer test2 = NbMES;
142 Handle(Draw_Drawable3D) D = Draw::Get(a[1],Standard_False);
143 Standard_Integer CurrentMES4 = SetName(a[1],di);
144 if(PAMES == NULL) { PAMES = new TestTopOpeTools_Array1OfMesure(1, 100); }
145 if((test2 < CurrentMES4) || // if nee measurement or if
146 (D.IsNull() && ((*PDel).Value(CurrentMES4) == "1"))) // after a "dall"
148 TestTopOpeTools_Mesure *MES4 = (new TestTopOpeTools_Mesure(a[1]));
149 (*MES4).Add(atoi(a[2]),atof(a[3]));
150 if((*PDel).Value(CurrentMES4) == "1") {
151 TestTopOpeTools_Mesure MES3;
152 MES3 = (*PAMES).Value(CurrentMES4);
155 (*PDel).SetValue(CurrentMES4, "0");
156 (*PAMES).SetValue(CurrentMES4, *MES4);
158 TestTopOpeTools_Mesure& MES4 = (*PAMES).ChangeValue(CurrentMES4);
159 MES4.Add(atoi(a[2]),atof(a[3]));
160 (*PAMES).SetValue(CurrentMES4, MES4);
165 else if (!strcmp(a[0],"seem")) {
166 if (na < 2) return 0;
167 TestTopOpeTools_Mesure MESS2;
168 Handle(Draw_Drawable3D) D;
169 Handle(TestTopOpeDraw_DrawableMesure) DMES2;
170 Standard_Integer test4, CurrentMESS2, i;
172 PAMES = new TestTopOpeTools_Array1OfMesure(1, 100);
176 CurrentMESS2 = SetName(a[i],di);
177 D = Draw::Get(a[i],Standard_False);
178 if(test4 < CurrentMESS2) {// if nee measurement, it is after restore
179 if(D.IsNull()) { return 0; }
180 DMES2 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
181 TestTopOpeTools_Mesure *MES;
182 MES = (new TestTopOpeTools_Mesure(DMES2->Pnts()));
184 (*PAMES).SetValue(CurrentMESS2, *MES);
186 MESS2 = (*PAMES).Value(CurrentMESS2);
188 DMES2 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
189 } else { // --> M is already in PAMES, and DMES has no name
190 DMES2 = new TestTopOpeDraw_DrawableMesure(MESS2, Draw_blanc,Draw_rose);
193 Draw::Set(a[i],DMES2);
194 (*PDel).SetValue(CurrentMESS2, "1");
198 else if (!strcmp(a[0],"seemx") || !strcmp(a[0],"seemy")) {
199 if (na < 3) return 0;
200 Standard_Real dx=1.,dy=1.;
201 Standard_Boolean isX = Standard_False, isY = Standard_False;
202 if (!strcmp(a[0],"seemx")) { dx = atof(a[na-1]); isX = Standard_True; }
203 else if (!strcmp(a[0],"seemy")) { dy = atof(a[na-1]); isY = Standard_True; }
204 TestTopOpeTools_Mesure MES5;
205 Handle(Draw_Drawable3D) D;
206 Handle(TestTopOpeDraw_DrawableMesure) DMES5;
207 Standard_Integer test, i;
208 if(PAMES == NULL) { PAMES = new TestTopOpeTools_Array1OfMesure(1, 100); }
209 for(i = 1; i < na-1; i++) {
211 Standard_Integer CurrentMES5 = SetName(a[i],di);
212 D = Draw::Get(a[i],Standard_False);
213 if(test < CurrentMES5) {// if new measurement, it is after restore
214 if(D.IsNull()) { return 0; }
215 DMES5 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
216 TestTopOpeTools_Mesure *MES;
217 MES = (new TestTopOpeTools_Mesure(DMES5->Pnts()));
219 (*PAMES).SetValue(CurrentMES5, *MES);
221 MES5 = (*PAMES).Value(CurrentMES5);
223 DMES5 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
225 DMES5 = new TestTopOpeDraw_DrawableMesure(MES5, Draw_blanc,Draw_rose);
228 Draw::Set(a[i],DMES5);
229 (*PDel).SetValue(CurrentMES5, "1");
230 if(isX) DMES5->SetScaleX(dx);
231 if(isY) DMES5->SetScaleY(dy);
234 else if (!strcmp(a[0],"seemxy")) {
235 if (na < 4) return 0;
236 TestTopOpeTools_Mesure& M = (*PAMES).ChangeValue(SetName(a[1],di));
237 Standard_Real dx=atof(a[2]),dy=atof(a[3]);
238 Handle(Draw_Drawable3D) D = Draw::Get(a[1],Standard_False);
239 Handle(TestTopOpeDraw_DrawableMesure) DM;
240 DM = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
242 DM = new TestTopOpeDraw_DrawableMesure(M,Draw_blanc,Draw_rose);
253 void TestTopOpe::MesureCommands(Draw_Interpretor& theCommands)
254 //=======================================================================
256 const char* g = "Topological Operation Mesure commands";
257 theCommands.Add("mesure","mesure M [n v] : create /add a data/ to a mesure",__FILE__,Mes,g);
258 theCommands.Add("seem","seem M : visualize mesure M",__FILE__,Mes,g);
259 theCommands.Add("seemx","seemx M ScaleX",__FILE__,Mes,g);
260 theCommands.Add("seemy","seemy M ScaleY",__FILE__,Mes,g);
261 theCommands.Add("seemxy","seemxy M ScaleX ScaleY",__FILE__,Mes,g);