0026922: Huge performance issue writing data to the output stream
[occt.git] / src / TestTopOpe / TestTopOpe_MesureCommands.cxx
CommitLineData
b311480e 1// Created on: 1996-10-21
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
18#include <Draw_Appli.hxx>
19#include <Draw_Interpretor.hxx>
7fd59977 20#include <DrawTrSurf_Curve.hxx>
7fd59977 21#include <TColStd_Array1OfAsciiString.hxx>
42cf5bc1 22#include <TColStd_Array1OfTransient.hxx>
23#include <TestTopOpe.hxx>
24#include <TestTopOpeDraw_Array1OfDrawableMesure.hxx>
25#include <TestTopOpeDraw_DrawableMesure.hxx>
26#include <TestTopOpeTools_HArray1OfMesure.hxx>
27#include <TestTopOpeTools_Mesure.hxx>
28#include <TopoDS_Shape.hxx>
29#include <TopOpeBRepBuild_HBuilder.hxx>
30#include <TopOpeBRepDS_HDataStructure.hxx>
7fd59977 31
57c28b61 32#ifdef _WIN32
7fd59977 33Standard_IMPORT Draw_Viewer dout;
34#endif
35
36
37//static Standard_Boolean Bool;
38static Standard_Integer NbMES = 0;
39static TColStd_Array1OfAsciiString *PDel = NULL;
40static TColStd_Array1OfAsciiString *PNAME = NULL;
41static TestTopOpeTools_Array1OfMesure *PAMES = NULL;
42
43//-----------------------------------------------
44static Standard_Integer SetName(const Standard_Character *C, Draw_Interpretor& di)
45//-----------------------------------------------
46// here the number of measurement is managed
47{
48 if(PNAME == NULL) {
49 PNAME = new TColStd_Array1OfAsciiString(1, 100);
50 }
51 if(PDel == NULL) {
52 PDel = new TColStd_Array1OfAsciiString(1, 100);
53 }
54 if(NbMES >= 100) {di << "ATTENTION : last measurement accepted";}
55 for(Standard_Integer i = 1; i <= NbMES; i++) {
56 Standard_Character *Ch = (Standard_Character *)(*PNAME).Value(i).ToCString();
57 if( *Ch == *C) return i;
58 }
59 (*PNAME).SetValue(++NbMES, *C);
60 (*PDel).SetValue(NbMES, "0");
61 return NbMES;
62}
63
7fd59977 64static void Mes_help(Draw_Interpretor& di)
65{
66 di<<"\n";
586db386 67 di<<"mesure M : create/reset measurement M \n";
68 di<<"mesure reset : reinitialize all measurements\n";
69 di<<"mesure M n t : add data [n t] to M\n";
70 di<<"mesure range M : sort indexes 'min max' of M\n";
71 di<<"mesure minmax M : take 'xmin ymin xmax ymax' from M\n";
72 di<<"mesure xy <i> M : take 'x y' = M(i)\n";
73 di<<"seem M : visualize M\n";
74 di<<"seemx M fx : visualize M with factor in x\n";
75 di<<"seemx M fy : visualize M with factor in y\n";
76 di<<"seemxy M fx fy : visualize M with factor in x,y\n";
77 di<<"\n";
7fd59977 78}
79
80// ----------------------------------------------------------------------
81Standard_Integer Mes(Draw_Interpretor& di,Standard_Integer na, const char** a)
82// ----------------------------------------------------------------------
83{
84 if (!strcmp(a[0],"mesure")) {
85 if (na == 1) {
86 Mes_help(di);
87 return 0;
88 }
89 else if (na == 2) {
90 if (!strcmp(a[1],"reset")) { PAMES = NULL; return 0;}
91 else {
92 Standard_Integer CurrentMES2 = SetName(a[1],di);
93 TestTopOpeTools_Mesure *MES2;
94 MES2 = new TestTopOpeTools_Mesure(a[1]);
95 if(PAMES == NULL) { PAMES = new TestTopOpeTools_Array1OfMesure(1, 100); }
96 (*PAMES).SetValue(CurrentMES2, *MES2);
97 }
98 }
99 else if (na == 3) {
100 if (!strcmp(a[1],"range")) {
101 const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[2],di));
102 di<<"1 "<<M.NPnts();
103 }
104 else if (!strcmp(a[1],"minmax")) {
105 const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[2],di));
106 Standard_Integer n=M.NPnts();
107 Standard_Real xm=0,ym=0,xM=0,yM=0;
108 if (n) {
109 xm=1.e100;ym=1.e100;xM=-1.e100;yM=-1.e100;
110 for (Standard_Integer i=1;i<=n;i++) {
111 Standard_Real x,y,z;gp_Pnt p=M.Pnt(i);p.Coord(x,y,z);
112 xm=Min(xm,x);xM=Max(xM,x);
113 ym=Min(ym,y);yM=Max(yM,y);
114 }
115 }
116 di<<xm<<" "<<ym<<" "<<xM<<" "<<yM;
117 }
118 }
119 else if (na == 4) {
120 if (!strcmp(a[1],"xy")) {
91322f44 121 Standard_Integer i = Draw::Atoi(a[2]);
7fd59977 122 const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[3],di));
123 Standard_Real x,y,z;gp_Pnt p=M.Pnt(i);p.Coord(x,y,z);
124 di<<x<<" "<<y;
125 return 0;
126 }
127 Standard_Integer test2 = NbMES;
128 Handle(Draw_Drawable3D) D = Draw::Get(a[1],Standard_False);
129 Standard_Integer CurrentMES4 = SetName(a[1],di);
130 if(PAMES == NULL) { PAMES = new TestTopOpeTools_Array1OfMesure(1, 100); }
131 if((test2 < CurrentMES4) || // if nee measurement or if
132 (D.IsNull() && ((*PDel).Value(CurrentMES4) == "1"))) // after a "dall"
133 {
134 TestTopOpeTools_Mesure *MES4 = (new TestTopOpeTools_Mesure(a[1]));
91322f44 135 (*MES4).Add(Draw::Atoi(a[2]),Draw::Atof(a[3]));
7fd59977 136 if((*PDel).Value(CurrentMES4) == "1") {
137 TestTopOpeTools_Mesure MES3;
138 MES3 = (*PAMES).Value(CurrentMES4);
139 MES3.Clear();
140 }
141 (*PDel).SetValue(CurrentMES4, "0");
142 (*PAMES).SetValue(CurrentMES4, *MES4);
143 } else {
144 TestTopOpeTools_Mesure& MES4 = (*PAMES).ChangeValue(CurrentMES4);
91322f44 145 MES4.Add(Draw::Atoi(a[2]),Draw::Atof(a[3]));
7fd59977 146 (*PAMES).SetValue(CurrentMES4, MES4);
147 }
148
149 }
150 }
151 else if (!strcmp(a[0],"seem")) {
152 if (na < 2) return 0;
153 TestTopOpeTools_Mesure MESS2;
154 Handle(Draw_Drawable3D) D;
155 Handle(TestTopOpeDraw_DrawableMesure) DMES2;
156 Standard_Integer test4, CurrentMESS2, i;
157 if(PAMES == NULL) {
158 PAMES = new TestTopOpeTools_Array1OfMesure(1, 100);
159 }
160 for (i=1;i<na;i++) {
161 test4 = NbMES;
162 CurrentMESS2 = SetName(a[i],di);
163 D = Draw::Get(a[i],Standard_False);
164 if(test4 < CurrentMESS2) {// if nee measurement, it is after restore
165 if(D.IsNull()) { return 0; }
166 DMES2 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
167 TestTopOpeTools_Mesure *MES;
168 MES = (new TestTopOpeTools_Mesure(DMES2->Pnts()));
169 MES->SetName(a[i]);
170 (*PAMES).SetValue(CurrentMESS2, *MES);
171 } else {
172 MESS2 = (*PAMES).Value(CurrentMESS2);
173 if(!D.IsNull()) {
174 DMES2 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
175 } else { // --> M is already in PAMES, and DMES has no name
176 DMES2 = new TestTopOpeDraw_DrawableMesure(MESS2, Draw_blanc,Draw_rose);
177 }
178 }
179 Draw::Set(a[i],DMES2);
180 (*PDel).SetValue(CurrentMESS2, "1");
181 }
182 dout.RepaintAll();
183 }
184 else if (!strcmp(a[0],"seemx") || !strcmp(a[0],"seemy")) {
185 if (na < 3) return 0;
186 Standard_Real dx=1.,dy=1.;
187 Standard_Boolean isX = Standard_False, isY = Standard_False;
91322f44 188 if (!strcmp(a[0],"seemx")) { dx = Draw::Atof(a[na-1]); isX = Standard_True; }
189 else if (!strcmp(a[0],"seemy")) { dy = Draw::Atof(a[na-1]); isY = Standard_True; }
7fd59977 190 TestTopOpeTools_Mesure MES5;
191 Handle(Draw_Drawable3D) D;
192 Handle(TestTopOpeDraw_DrawableMesure) DMES5;
193 Standard_Integer test, i;
194 if(PAMES == NULL) { PAMES = new TestTopOpeTools_Array1OfMesure(1, 100); }
195 for(i = 1; i < na-1; i++) {
196 test = NbMES;
197 Standard_Integer CurrentMES5 = SetName(a[i],di);
198 D = Draw::Get(a[i],Standard_False);
199 if(test < CurrentMES5) {// if new measurement, it is after restore
200 if(D.IsNull()) { return 0; }
201 DMES5 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
202 TestTopOpeTools_Mesure *MES;
203 MES = (new TestTopOpeTools_Mesure(DMES5->Pnts()));
204 MES->SetName(a[i]);
205 (*PAMES).SetValue(CurrentMES5, *MES);
206 } else {
207 MES5 = (*PAMES).Value(CurrentMES5);
208 if(!D.IsNull()) {
209 DMES5 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
210 } else {
211 DMES5 = new TestTopOpeDraw_DrawableMesure(MES5, Draw_blanc,Draw_rose);
212 }
213 }
214 Draw::Set(a[i],DMES5);
215 (*PDel).SetValue(CurrentMES5, "1");
216 if(isX) DMES5->SetScaleX(dx);
217 if(isY) DMES5->SetScaleY(dy);
218 }
219 }
220 else if (!strcmp(a[0],"seemxy")) {
221 if (na < 4) return 0;
222 TestTopOpeTools_Mesure& M = (*PAMES).ChangeValue(SetName(a[1],di));
91322f44 223 Standard_Real dx=Draw::Atof(a[2]),dy=Draw::Atof(a[3]);
7fd59977 224 Handle(Draw_Drawable3D) D = Draw::Get(a[1],Standard_False);
225 Handle(TestTopOpeDraw_DrawableMesure) DM;
226 DM = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
227 if (DM.IsNull()) {
228 DM = new TestTopOpeDraw_DrawableMesure(M,Draw_blanc,Draw_rose);
229 Draw::Set(a[1],DM);
230 }
231 DM->SetScaleX(dx);
232 DM->SetScaleY(dy);
233 dout<<DM;
234 }
235
236 return 0;
237}
238
239void TestTopOpe::MesureCommands(Draw_Interpretor& theCommands)
240 //=======================================================================
241{
242 const char* g = "Topological Operation Mesure commands";
243 theCommands.Add("mesure","mesure M [n v] : create /add a data/ to a mesure",__FILE__,Mes,g);
244 theCommands.Add("seem","seem M : visualize mesure M",__FILE__,Mes,g);
245 theCommands.Add("seemx","seemx M ScaleX",__FILE__,Mes,g);
246 theCommands.Add("seemy","seemy M ScaleY",__FILE__,Mes,g);
247 theCommands.Add("seemxy","seemxy M ScaleX ScaleY",__FILE__,Mes,g);
248}