Porting samples for OCCT 6.5.2
[occt.git] / samples / mfc / standard / 01_Geometry / src / GeometryDoc.cpp
CommitLineData
7fd59977 1// GeometryDoc.cpp : implementation of the CGeometryDoc class
2//
3
4#include "stdafx.h"
5
6#include "GeometryDoc.h"
7#include "GeoAlgo_Sol.hxx"
8#include "GeometryApp.h"
9#include "GeometryView2D.h"
10#include "GeometryView.h"
11
12#ifdef _DEBUG
13#undef THIS_FILE
14static char THIS_FILE[] = __FILE__;
15#endif
16#include "GeomSources.h"
17
18#ifdef WNT
19 #define EOL "\r\n"
20#else
21 #define EOL "\n"
22#endif
23
24#define WAIT_A_LITTLE WaitForInput(500)
25
26#define MAX_PARAM 1000 // if a surface parameter is infinite, it is assingned
27// this value in order to display the "infinit" object in the viewer.
28
29/////////////////////////////////////////////////////////////////////////////
30// CGeometryDoc
31
32IMPLEMENT_DYNCREATE(CGeometryDoc, CDocument)
33
34BEGIN_MESSAGE_MAP(CGeometryDoc, CDocument)
35 //{{AFX_MSG_MAP(CGeometryDoc)
36 ON_COMMAND(ID_WINDOW_NEW2D, OnWindowNew2d)
37 ON_COMMAND(ID_BUTTON_Test_1, OnBUTTONTest1)
38 ON_COMMAND(ID_BUTTON_Test_2, OnBUTTONTest2)
39 ON_COMMAND(ID_BUTTON_Test_3, OnBUTTONTest3)
40 ON_COMMAND(ID_BUTTON_Test_4, OnBUTTONTest4)
41 ON_COMMAND(ID_BUTTON_Test_5, OnBUTTONTest5)
42 ON_COMMAND(ID_BUTTON_Test_6, OnBUTTONTest6)
43 ON_COMMAND(ID_BUTTON_Test_7, OnBUTTONTest7)
44 ON_COMMAND(ID_BUTTON_Test_8, OnBUTTONTest8)
45 ON_COMMAND(ID_BUTTON_Test_9, OnBUTTONTest9)
46 ON_COMMAND(ID_BUTTON_Test_23, OnBUTTONTest23)
47 ON_COMMAND(ID_BUTTON_Test_22, OnBUTTONTest22)
48 ON_COMMAND(ID_BUTTON_Test_10, OnBUTTONTest10)
49 ON_COMMAND(ID_BUTTON_Test_11, OnBUTTONTest11)
50 ON_COMMAND(ID_BUTTON_Test_12, OnBUTTONTest12)
51 ON_COMMAND(ID_BUTTON_Test_13, OnBUTTONTest13)
52 ON_COMMAND(ID_BUTTON_Test_14, OnBUTTONTest14)
53 ON_COMMAND(ID_BUTTON_Test_15, OnBUTTONTest15)
54 ON_COMMAND(ID_BUTTON_Test_16, OnBUTTONTest16)
55 ON_COMMAND(ID_BUTTON_Test_17, OnBUTTONTest17)
56 ON_COMMAND(ID_BUTTON_Test_18, OnBUTTONTest18)
57 ON_COMMAND(ID_BUTTON_Test_19, OnBUTTONTest19)
58 ON_COMMAND(ID_BUTTON_Test_20, OnBUTTONTest20)
59 ON_COMMAND(ID_BUTTON_Test_21, OnBUTTONTest21)
60 ON_COMMAND(ID_BUTTON_Test_24, OnBUTTONTest24)
61 ON_COMMAND(ID_BUTTON_Test_25, OnBUTTONTest25)
62 ON_COMMAND(ID_BUTTON_Test_26, OnBUTTONTest26)
63 ON_COMMAND(ID_BUTTON_Test_27, OnBUTTONTest27)
64 ON_COMMAND(ID_BUTTON_Test_28, OnBUTTONTest28)
65 ON_COMMAND(ID_BUTTON_Test_29, OnBUTTONTest29)
66 ON_COMMAND(ID_BUTTON_Test_30, OnBUTTONTest30)
67 ON_COMMAND(ID_BUTTON_Test_31, OnBUTTONTest31)
68 ON_COMMAND(ID_BUTTON_Test_32, OnBUTTONTest32)
69 ON_COMMAND(ID_BUTTON_Test_33, OnBUTTONTest33)
70 ON_COMMAND(ID_BUTTON_Test_34, OnBUTTONTest34)
71 ON_COMMAND(ID_BUTTON_Test_35, OnBUTTONTest35)
72 ON_COMMAND(ID_BUTTON_Test_36, OnBUTTONTest36)
73 ON_COMMAND(ID_BUTTON_Test_37, OnBUTTONTest37)
74 ON_COMMAND(ID_BUTTON_Test_38, OnBUTTONTest38)
75 ON_COMMAND(ID_BUTTON_Test_39, OnBUTTONTest39)
76 ON_COMMAND(ID_BUTTON_Test_40, OnBUTTONTest40)
77 ON_COMMAND(ID_BUTTON_Test_41, OnBUTTONTest41)
78 ON_COMMAND(ID_BUTTON_Test_42, OnBUTTONTest42)
79 ON_COMMAND(ID_BUTTON_Test_43, OnBUTTONTest43)
80 ON_COMMAND(ID_BUTTON_Test_44, OnBUTTONTest44)
81 ON_COMMAND(ID_BUTTON_Test_45, OnBUTTONTest45)
82 ON_COMMAND(ID_BUTTON_Test_46, OnBUTTONTest46)
83 ON_COMMAND(ID_BUTTON_Test_47, OnBUTTONTest47)
84 ON_COMMAND(ID_BUTTON_Test_48, OnBUTTONTest48)
85 ON_COMMAND(ID_BUTTON_Test_49, OnBUTTONTest49)
86 ON_COMMAND(ID_BUTTON_Test_50, OnBUTTONTest50)
87 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_1 , OnUpdateBUTTONTest1 )
88 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_2 , OnUpdateBUTTONTest2 )
89 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_3 , OnUpdateBUTTONTest3 )
90 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_4 , OnUpdateBUTTONTest4 )
91 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_5 , OnUpdateBUTTONTest5 )
92 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_6 , OnUpdateBUTTONTest6 )
93 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_7 , OnUpdateBUTTONTest7 )
94 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_8 , OnUpdateBUTTONTest8 )
95 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_9 , OnUpdateBUTTONTest9 )
96 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_10 , OnUpdateBUTTONTest10 )
97 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_11 , OnUpdateBUTTONTest11 )
98 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_12 , OnUpdateBUTTONTest12 )
99 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_13 , OnUpdateBUTTONTest13 )
100 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_14 , OnUpdateBUTTONTest14 )
101 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_15 , OnUpdateBUTTONTest15 )
102 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_16 , OnUpdateBUTTONTest16 )
103 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_17 , OnUpdateBUTTONTest17 )
104 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_18 , OnUpdateBUTTONTest18 )
105 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_19 , OnUpdateBUTTONTest19 )
106 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_20 , OnUpdateBUTTONTest20 )
107 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_21 , OnUpdateBUTTONTest21 )
108 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_22 , OnUpdateBUTTONTest22 )
109 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_23 , OnUpdateBUTTONTest23 )
110 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_24 , OnUpdateBUTTONTest24 )
111 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_25 , OnUpdateBUTTONTest25 )
112 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_26 , OnUpdateBUTTONTest26 )
113 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_27 , OnUpdateBUTTONTest27 )
114 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_28 , OnUpdateBUTTONTest28 )
115 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_29 , OnUpdateBUTTONTest29 )
116 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_30 , OnUpdateBUTTONTest30 )
117 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_31 , OnUpdateBUTTONTest31 )
118 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_32 , OnUpdateBUTTONTest32 )
119 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_33 , OnUpdateBUTTONTest33 )
120 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_34 , OnUpdateBUTTONTest34 )
121 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_35 , OnUpdateBUTTONTest35 )
122 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_36 , OnUpdateBUTTONTest36 )
123 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_37 , OnUpdateBUTTONTest37 )
124 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_38 , OnUpdateBUTTONTest38 )
125 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_39 , OnUpdateBUTTONTest39 )
126 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_40 , OnUpdateBUTTONTest40 )
127 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_41 , OnUpdateBUTTONTest41 )
128 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_42 , OnUpdateBUTTONTest42 )
129 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_43 , OnUpdateBUTTONTest43 )
130 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_44 , OnUpdateBUTTONTest44 )
131 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_45 , OnUpdateBUTTONTest45 )
132 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_46 , OnUpdateBUTTONTest46 )
133 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_47 , OnUpdateBUTTONTest47 )
134 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_48 , OnUpdateBUTTONTest48 )
135 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_49 , OnUpdateBUTTONTest49 )
136 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_50 , OnUpdateBUTTONTest50 )
137 ON_COMMAND(ID_Create_Sol, OnCreateSol)
138 ON_COMMAND(ID_BUTTON_Simplify, OnSimplify)
139 //}}AFX_MSG_MAP
140END_MESSAGE_MAP()
141
142/////////////////////////////////////////////////////////////////////////////
143// CGeometryDoc construction/destruction
144
145CGeometryDoc::CGeometryDoc()
146{
147 FitMode = false;
148
149 AfxInitRichEdit();
150
151 // TODO: add one-time construction code here
152 Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
153 ((CGeometryApp*)AfxGetApp())->GetGraphicDevice();
154
155 TCollection_ExtendedString a3DName("Visu3D");
156 myViewer = new V3d_Viewer(theGraphicDevice,a3DName.ToExtString());
157 myViewer->SetDefaultLights();
158 myViewer->SetLightOn();
159
160 myAISContext =new AIS_InteractiveContext(myViewer);
161 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(11);
162 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(11);
163
164 TCollection_ExtendedString a2DName("Visu2D");
165 myViewer2D = new V2d_Viewer(theGraphicDevice,a2DName.ToExtString());
166 myViewer2D->SetCircularGridValues(0,0,1,8,0);
167 myViewer2D->SetRectangularGridValues(0,0,1,1,0);
168 myISessionContext= new ISession2D_InteractiveContext(myViewer2D);
169 myCResultDialog.Create(CResultDialog::IDD,NULL);
170
171 RECT dlgrect;
172 myCResultDialog.GetWindowRect(&dlgrect);
173 LONG width = dlgrect.right-dlgrect.left;
174 LONG height = dlgrect.bottom-dlgrect.top;
175 RECT MainWndRect;
176 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
177 LONG left = MainWndRect.left+3;
178 LONG top = MainWndRect.top + 138;
179 myCResultDialog.MoveWindow(left,top,width,height);
180
181 ((CGeometryApp*)AfxGetApp())->CreateView2D(this);
182 Minimize2D();
183 Put3DOnTop();
184}
185
186CGeometryDoc::~CGeometryDoc()
187{
188}
189
190BOOL CGeometryDoc::OnNewDocument()
191{
192 if (!CDocument::OnNewDocument())
193 return FALSE;
194
195 // TODO: add reinitialization code here
196 // (SDI documents will reuse this document)
197 // compute a graphic device --> the same for all Views
198
199 return TRUE;
200}
201
202
203
204void CGeometryDoc::OnWindowNew2d()
205{
206
207 ((CGeometryApp*)AfxGetApp())->CreateView2D(this);
208}
209
210/////////////////////////////////////////////////////////////////////////////
211// CGeometryDoc serialization
212
213void CGeometryDoc::Serialize(CArchive& ar)
214{
215 if (ar.IsStoring())
216 {
217 // TODO: add storing code here
218 }
219 else
220 {
221 // TODO: add loading code here
222 }
223}
224
225/////////////////////////////////////////////////////////////////////////////
226// CGeometryDoc diagnostics
227
228#ifdef _DEBUG
229void CGeometryDoc::AssertValid() const
230{
231 CDocument::AssertValid();
232}
233
234void CGeometryDoc::Dump(CDumpContext& dc) const
235{
236 CDocument::Dump(dc);
237}
238#endif //_DEBUG
239
240/////////////////////////////////////////////////////////////////////////////
241// CGeometryDoc commands
242
243//-----------------------------------------------------------------------------------------
244//
245//-----------------------------------------------------------------------------------------
246void CGeometryDoc::DragEvent2D(const Standard_Integer x ,
247 const Standard_Integer y ,
248 const Standard_Integer TheState ,
249 const Handle(V2d_View)& aView )
250{
251}
252
253
254//-----------------------------------------------------------------------------------------
255//
256//-----------------------------------------------------------------------------------------
257void CGeometryDoc::InputEvent2D(const Standard_Integer x ,
258 const Standard_Integer y ,
259 const Handle(V2d_View)& aView )
260{
261 myISessionContext->Pick(aView,x,y);
262}
263
264//-----------------------------------------------------------------------------------------
265//
266//-----------------------------------------------------------------------------------------
267void CGeometryDoc::MoveEvent2D(const Standard_Integer x ,
268 const Standard_Integer y ,
269 const Handle(V2d_View)& aView )
270{
271 myISessionContext->Move(aView,x,y);
272}
273
274//-----------------------------------------------------------------------------------------
275//
276//-----------------------------------------------------------------------------------------
277void CGeometryDoc::ShiftMoveEvent2D(const Standard_Integer x ,
278 const Standard_Integer y ,
279 const Handle(V2d_View)& aView )
280{
281}
282
283//-----------------------------------------------------------------------------------------
284//
285//-----------------------------------------------------------------------------------------
286void CGeometryDoc::ShiftDragEvent2D(const Standard_Integer x ,
287 const Standard_Integer y ,
288 const Standard_Integer TheState ,
289 const Handle(V2d_View)& aView )
290{
291}
292
293
294//-----------------------------------------------------------------------------------------
295//
296//-----------------------------------------------------------------------------------------
297void CGeometryDoc::ShiftInputEvent2D(const Standard_Integer x ,
298 const Standard_Integer y ,
299 const Handle(V2d_View)& aView )
300{
301}
302
303//-----------------------------------------------------------------------------------------
304//
305//-----------------------------------------------------------------------------------------
306void CGeometryDoc::Popup2D(const Standard_Integer x,
307 const Standard_Integer y ,
308 const Handle(V2d_View)& aView )
309{
310
311 CMenu menu;
312 VERIFY(menu.LoadMenu(IDR_Popup3D));
313 CMenu* pPopup;
314
315 pPopup = menu.GetSubMenu(0);
316
317 ASSERT(pPopup != NULL);
318
319 POINT winCoord = { x , y };
320 Handle(WNT_Window) aWNTWindow=
321 Handle(WNT_Window)::DownCast(aView->Driver()->Window());
322 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
323 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
324 AfxGetMainWnd());
325
326}
327
328void CGeometryDoc::Put2DOnTop(bool isMax)
329{
330 POSITION position = GetFirstViewPosition();
331 while (position != (POSITION)NULL)
332 {
333 CView* pCurrentView = (CView*)GetNextView(position);
334 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
335 {
336 ASSERT_VALID(pCurrentView);
337 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
338 ASSERT(pParentFrm != (CFrameWnd *)NULL);
339 // simply make the frame window visible
340 if(isMax) {
341 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
342 } else {
343 pParentFrm->ActivateFrame(SW_SHOW);
344 }
345 }
346 }
347}
348
349void CGeometryDoc::Minimize2D()
350{
351 POSITION position = GetFirstViewPosition();
352 while (position != (POSITION)NULL)
353 {
354 CView* pCurrentView = (CView*)GetNextView(position);
355 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
356 {
357 ASSERT_VALID(pCurrentView);
358 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
359 ASSERT(pParentFrm != (CFrameWnd *)NULL);
360 // simply make the frame window visible
361 pParentFrm->ActivateFrame(SW_HIDE);
362 }
363 }
364
365}
366
367void CGeometryDoc::Fit2DViews()
368{
369 POSITION position = GetFirstViewPosition();
370 while (position != (POSITION)NULL)
371 {
372 CView* pCurrentView = (CView*)GetNextView(position);
373 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
374 {
375 ASSERT_VALID(pCurrentView);
376 CGeometryView2D* aCGeometryView2D = (CGeometryView2D*)pCurrentView;
377 aCGeometryView2D->FitAll();
378 }
379 }
380
381}
382void CGeometryDoc::Put3DOnTop(bool isMax)
383{
384 POSITION position = GetFirstViewPosition();
385 while (position != (POSITION)NULL)
386 {
387 CView* pCurrentView = (CView*)GetNextView(position);
388 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
389 {
390 ASSERT_VALID(pCurrentView);
391 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
392 ASSERT(pParentFrm != (CFrameWnd *)NULL);
393 // simply make the frame window visible
394 if(isMax) {
395 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
396 } else {
397 pParentFrm->ActivateFrame(SW_SHOW);
398 }
399 }
400 }
401}
402void CGeometryDoc::Minimize3D()
403{
404 POSITION position = GetFirstViewPosition();
405 while (position != (POSITION)NULL)
406 {
407 CView* pCurrentView = (CView*)GetNextView(position);
408 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
409 {
410 ASSERT_VALID(pCurrentView);
411 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
412 ASSERT(pParentFrm != (CFrameWnd *)NULL);
413 // simply make the frame window visible
414 pParentFrm->ActivateFrame(SW_HIDE);
415 }
416 }
417
418}
419
420
421void CGeometryDoc::Fit3DViews(Quantity_Coefficient Coef)
422{
423 POSITION position = GetFirstViewPosition();
424 while (position != (POSITION)NULL)
425 {
426 CView* pCurrentView = (CView*)GetNextView(position);
427 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
428 {
429 ASSERT_VALID(pCurrentView);
430 CGeometryView* aCGeometryView = (CGeometryView*)pCurrentView;
431 aCGeometryView->FitAll(Coef);
432 }
433 }
434
435}
436void CGeometryDoc::Set3DViewsZoom(const Quantity_Factor& Coef )
437{
438 POSITION position = GetFirstViewPosition();
439 while (position != (POSITION)NULL)
440 {
441 CView* pCurrentView = (CView*)GetNextView(position);
442 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
443 {
444 ASSERT_VALID(pCurrentView);
445 CGeometryView* aCGeometryView = (CGeometryView*)pCurrentView;
446 aCGeometryView->SetZoom( Coef );
447 }
448 }
449
450}
451
452void CGeometryDoc::OnBUTTONTest1()
453{ Current = 1;
454 GeomSources::gpTest1(this); }
455void CGeometryDoc::OnBUTTONTest2()
456{ Current = 2;
457 GeomSources::gpTest2(this); }
458void CGeometryDoc::OnBUTTONTest3()
459{ Current = 3;
460 GeomSources::gpTest3(this); }
461void CGeometryDoc::OnBUTTONTest4()
462{ Current = 4;
463 GeomSources::gpTest4(this); }
464void CGeometryDoc::OnBUTTONTest5()
465{ Current = 5;
466 GeomSources::gpTest5(this); }
467void CGeometryDoc::OnBUTTONTest6()
468{ Current = 6;
469 GeomSources::gpTest6(this); }
470void CGeometryDoc::OnBUTTONTest7()
471{ Current = 7;
472 GeomSources::gpTest7(this); }
473void CGeometryDoc::OnBUTTONTest8()
474{ Current = 8;
475 GeomSources::gpTest8(this); }
476void CGeometryDoc::OnBUTTONTest9()
477{ Current = 9;
478 GeomSources::gpTest9(this); }
479void CGeometryDoc::OnBUTTONTest10()
480{ Current = 10;
481 GeomSources::gpTest10(this); }
482void CGeometryDoc::OnBUTTONTest11()
483{ Current = 11;
484 GeomSources::gpTest11(this); }
485void CGeometryDoc::OnBUTTONTest12()
486{ Current = 12;
487 GeomSources::gpTest12(this); }
488void CGeometryDoc::OnBUTTONTest13()
489{ Current = 13;
490 GeomSources::gpTest13(this); }
491void CGeometryDoc::OnBUTTONTest14()
492{ Current = 14;
493 GeomSources::gpTest14(this); }
494void CGeometryDoc::OnBUTTONTest15()
495{ Current = 15;
496 GeomSources::gpTest15(this); }
497void CGeometryDoc::OnBUTTONTest16()
498{ Current = 16;
499 GeomSources::gpTest16(this); }
500void CGeometryDoc::OnBUTTONTest17()
501{ Current = 17;
502 GeomSources::gpTest17(this); }
503void CGeometryDoc::OnBUTTONTest18()
504{ Current = 18;
505 GeomSources::gpTest18(this); }
506void CGeometryDoc::OnBUTTONTest19()
507{ Current = 19;
508 GeomSources::gpTest19(this); }
509void CGeometryDoc::OnBUTTONTest20()
510{ Current = 20;
511 GeomSources::gpTest20(this); }
512void CGeometryDoc::OnBUTTONTest21()
513{ Current = 21;
514 GeomSources::gpTest21(this); }
515void CGeometryDoc::OnBUTTONTest22()
516{ Current = 22;
517 GeomSources::gpTest22(this); }
518void CGeometryDoc::OnBUTTONTest23()
519{ Current = 23;
520 GeomSources::gpTest23(this); }
521void CGeometryDoc::OnBUTTONTest24()
522{ Current = 24;
523 GeomSources::gpTest24(this); }
524void CGeometryDoc::OnBUTTONTest25()
525{ Current = 25;
526 GeomSources::gpTest25(this); }
527void CGeometryDoc::OnBUTTONTest26()
528{ Current = 26;
529 GeomSources::gpTest26(this); }
530void CGeometryDoc::OnBUTTONTest27()
531{ Current = 27;
532 GeomSources::gpTest27(this); }
533void CGeometryDoc::OnBUTTONTest28()
534{ Current = 28;
535 GeomSources::gpTest28(this); }
536void CGeometryDoc::OnBUTTONTest29()
537{ Current = 29;
538 GeomSources::gpTest29(this); }
539void CGeometryDoc::OnBUTTONTest30()
540{ Current = 30;
541 GeomSources::gpTest30(this); }
542void CGeometryDoc::OnBUTTONTest31()
543{ Current = 31;
544 GeomSources::gpTest31(this); }
545void CGeometryDoc::OnBUTTONTest32()
546{ Current = 32;
547 GeomSources::gpTest32(this); }
548void CGeometryDoc::OnBUTTONTest33()
549{ Current = 33;
550 GeomSources::gpTest33(this); }
551void CGeometryDoc::OnBUTTONTest34()
552{ Current = 34;
553 GeomSources::gpTest34(this); }
554void CGeometryDoc::OnBUTTONTest35()
555{ Current = 35;
556 GeomSources::gpTest35(this); }
557void CGeometryDoc::OnBUTTONTest36()
558{ Current = 36;
559 GeomSources::gpTest36(this); }
560
561void CGeometryDoc::OnBUTTONTest37()
562{ Current = 37;
563 GeomSources::gpTest37(this); }
564void CGeometryDoc::OnBUTTONTest38()
565{ Current = 38;
566 GeomSources::gpTest38(this); }
567void CGeometryDoc::OnBUTTONTest39()
568{ Current = 39;
569 GeomSources::gpTest39(this); }
570void CGeometryDoc::OnBUTTONTest40()
571{ Current = 40;
572 GeomSources::gpTest40(this); }
573void CGeometryDoc::OnBUTTONTest41()
574{ Current = 41;
575 GeomSources::gpTest41(this); }
576void CGeometryDoc::OnBUTTONTest42()
577{ Current = 42;
578 GeomSources::gpTest42(this); }
579void CGeometryDoc::OnBUTTONTest43()
580{ Current = 43;
581 GeomSources::gpTest43(this); }
582void CGeometryDoc::OnBUTTONTest44()
583{ Current = 44;
584 GeomSources::gpTest44(this); }
585void CGeometryDoc::OnBUTTONTest45()
586{ Current = 45;
587 GeomSources::gpTest45(this); }
588void CGeometryDoc::OnBUTTONTest46()
589{ Current = 46;
590 GeomSources::gpTest46(this); }
591void CGeometryDoc::OnBUTTONTest47()
592{ Current = 47;
593 GeomSources::gpTest47(this); }
594void CGeometryDoc::OnBUTTONTest48()
595{ Current = 48;
596 GeomSources::gpTest48(this); }
597void CGeometryDoc::OnBUTTONTest49()
598{ Current = 49;
599 GeomSources::gpTest49(this); }
600void CGeometryDoc::OnBUTTONTest50()
601{ Current = 50;
602 GeomSources::gpTest50(this); }
603
604void CGeometryDoc::OnUpdateBUTTONTest1(CCmdUI* pCmdUI)
605{ if (Current == 1) pCmdUI->SetCheck(true);
606 else pCmdUI->SetCheck(false);
607}
608
609void CGeometryDoc::OnUpdateBUTTONTest2(CCmdUI* pCmdUI)
610{ if (Current == 2) pCmdUI->SetCheck(true);
611 else pCmdUI->SetCheck(false);
612}
613
614void CGeometryDoc::OnUpdateBUTTONTest3(CCmdUI* pCmdUI)
615{ if (Current == 3) pCmdUI->SetCheck(true);
616 else pCmdUI->SetCheck(false);
617}
618
619void CGeometryDoc::OnUpdateBUTTONTest4(CCmdUI* pCmdUI)
620{ if (Current == 4) pCmdUI->SetCheck(true);
621 else pCmdUI->SetCheck(false);
622}
623
624void CGeometryDoc::OnUpdateBUTTONTest5(CCmdUI* pCmdUI)
625{ if (Current == 5) pCmdUI->SetCheck(true);
626 else pCmdUI->SetCheck(false);
627}
628
629void CGeometryDoc::OnUpdateBUTTONTest6(CCmdUI* pCmdUI)
630{ if (Current == 6) pCmdUI->SetCheck(true);
631 else pCmdUI->SetCheck(false);
632}
633
634void CGeometryDoc::OnUpdateBUTTONTest7(CCmdUI* pCmdUI)
635{ if (Current == 7) pCmdUI->SetCheck(true);
636 else pCmdUI->SetCheck(false);
637}
638
639void CGeometryDoc::OnUpdateBUTTONTest8(CCmdUI* pCmdUI)
640{ if (Current == 8) pCmdUI->SetCheck(true);
641 else pCmdUI->SetCheck(false);
642}
643
644void CGeometryDoc::OnUpdateBUTTONTest9(CCmdUI* pCmdUI)
645{ if (Current == 9) pCmdUI->SetCheck(true);
646 else pCmdUI->SetCheck(false);
647}
648
649void CGeometryDoc::OnUpdateBUTTONTest10(CCmdUI* pCmdUI)
650{ if (Current == 10) pCmdUI->SetCheck(true);
651 else pCmdUI->SetCheck(false);
652}
653
654void CGeometryDoc::OnUpdateBUTTONTest11(CCmdUI* pCmdUI)
655{ if (Current == 11) pCmdUI->SetCheck(true);
656 else pCmdUI->SetCheck(false);
657}
658
659void CGeometryDoc::OnUpdateBUTTONTest12(CCmdUI* pCmdUI)
660{ if (Current == 12) pCmdUI->SetCheck(true);
661 else pCmdUI->SetCheck(false);
662}
663
664void CGeometryDoc::OnUpdateBUTTONTest13(CCmdUI* pCmdUI)
665{ if (Current == 13) pCmdUI->SetCheck(true);
666 else pCmdUI->SetCheck(false);
667}
668
669void CGeometryDoc::OnUpdateBUTTONTest14(CCmdUI* pCmdUI)
670{ if (Current == 14) pCmdUI->SetCheck(true);
671 else pCmdUI->SetCheck(false);
672}
673
674void CGeometryDoc::OnUpdateBUTTONTest15(CCmdUI* pCmdUI)
675{ if (Current == 15) pCmdUI->SetCheck(true);
676 else pCmdUI->SetCheck(false);
677}
678
679void CGeometryDoc::OnUpdateBUTTONTest16(CCmdUI* pCmdUI)
680{ if (Current == 16) pCmdUI->SetCheck(true);
681 else pCmdUI->SetCheck(false);
682}
683
684void CGeometryDoc::OnUpdateBUTTONTest17(CCmdUI* pCmdUI)
685{ if (Current == 17) pCmdUI->SetCheck(true);
686 else pCmdUI->SetCheck(false);
687}
688
689void CGeometryDoc::OnUpdateBUTTONTest18(CCmdUI* pCmdUI)
690{ if (Current == 18) pCmdUI->SetCheck(true);
691 else pCmdUI->SetCheck(false);
692}
693
694void CGeometryDoc::OnUpdateBUTTONTest19(CCmdUI* pCmdUI)
695{ if (Current == 19) pCmdUI->SetCheck(true);
696 else pCmdUI->SetCheck(false);
697}
698
699void CGeometryDoc::OnUpdateBUTTONTest20(CCmdUI* pCmdUI)
700{ if (Current == 20) pCmdUI->SetCheck(true);
701 else pCmdUI->SetCheck(false);
702}
703
704void CGeometryDoc::OnUpdateBUTTONTest21(CCmdUI* pCmdUI)
705{ if (Current == 21) pCmdUI->SetCheck(true);
706 else pCmdUI->SetCheck(false);
707}
708
709void CGeometryDoc::OnUpdateBUTTONTest22(CCmdUI* pCmdUI)
710{ if (Current == 22) pCmdUI->SetCheck(true);
711 else pCmdUI->SetCheck(false);
712}
713
714void CGeometryDoc::OnUpdateBUTTONTest23(CCmdUI* pCmdUI)
715{ if (Current == 23) pCmdUI->SetCheck(true);
716 else pCmdUI->SetCheck(false);
717}
718
719void CGeometryDoc::OnUpdateBUTTONTest24(CCmdUI* pCmdUI)
720{ if (Current == 24) pCmdUI->SetCheck(true);
721 else pCmdUI->SetCheck(false);
722}
723
724void CGeometryDoc::OnUpdateBUTTONTest25(CCmdUI* pCmdUI)
725{ if (Current == 25) pCmdUI->SetCheck(true);
726 else pCmdUI->SetCheck(false);
727}
728
729void CGeometryDoc::OnUpdateBUTTONTest26(CCmdUI* pCmdUI)
730{ if (Current == 26) pCmdUI->SetCheck(true);
731 else pCmdUI->SetCheck(false);
732}
733
734void CGeometryDoc::OnUpdateBUTTONTest27(CCmdUI* pCmdUI)
735{ if (Current == 27) pCmdUI->SetCheck(true);
736 else pCmdUI->SetCheck(false);
737}
738
739void CGeometryDoc::OnUpdateBUTTONTest28(CCmdUI* pCmdUI)
740{ if (Current == 28) pCmdUI->SetCheck(true);
741 else pCmdUI->SetCheck(false);
742}
743
744void CGeometryDoc::OnUpdateBUTTONTest29(CCmdUI* pCmdUI)
745{ if (Current == 29) pCmdUI->SetCheck(true);
746 else pCmdUI->SetCheck(false);
747}
748
749void CGeometryDoc::OnUpdateBUTTONTest30(CCmdUI* pCmdUI)
750{ if (Current == 30) pCmdUI->SetCheck(true);
751 else pCmdUI->SetCheck(false);
752}
753
754void CGeometryDoc::OnUpdateBUTTONTest31(CCmdUI* pCmdUI)
755{ if (Current == 31) pCmdUI->SetCheck(true);
756 else pCmdUI->SetCheck(false);
757}
758
759void CGeometryDoc::OnUpdateBUTTONTest32(CCmdUI* pCmdUI)
760{ if (Current == 32) pCmdUI->SetCheck(true);
761 else pCmdUI->SetCheck(false);
762}
763
764void CGeometryDoc::OnUpdateBUTTONTest33(CCmdUI* pCmdUI)
765{ if (Current == 33) pCmdUI->SetCheck(true);
766 else pCmdUI->SetCheck(false);
767}
768
769void CGeometryDoc::OnUpdateBUTTONTest34(CCmdUI* pCmdUI)
770{ if (Current == 34) pCmdUI->SetCheck(true);
771 else pCmdUI->SetCheck(false);
772}
773
774void CGeometryDoc::OnUpdateBUTTONTest35(CCmdUI* pCmdUI)
775{ if (Current == 35) pCmdUI->SetCheck(true);
776 else pCmdUI->SetCheck(false);
777}
778
779void CGeometryDoc::OnUpdateBUTTONTest36(CCmdUI* pCmdUI)
780{ if (Current == 36) pCmdUI->SetCheck(true);
781 else pCmdUI->SetCheck(false);
782}
783
784void CGeometryDoc::OnUpdateBUTTONTest37(CCmdUI* pCmdUI)
785{ if (Current == 37) pCmdUI->SetCheck(true);
786 else pCmdUI->SetCheck(false);
787}
788
789void CGeometryDoc::OnUpdateBUTTONTest38(CCmdUI* pCmdUI)
790{ if (Current == 38) pCmdUI->SetCheck(true);
791 else pCmdUI->SetCheck(false);
792}
793
794void CGeometryDoc::OnUpdateBUTTONTest39(CCmdUI* pCmdUI)
795{ if (Current == 39) pCmdUI->SetCheck(true);
796 else pCmdUI->SetCheck(false);
797}
798
799void CGeometryDoc::OnUpdateBUTTONTest40(CCmdUI* pCmdUI)
800{ if (Current == 40) pCmdUI->SetCheck(true);
801 else pCmdUI->SetCheck(false);
802}
803
804void CGeometryDoc::OnUpdateBUTTONTest41(CCmdUI* pCmdUI)
805{ if (Current == 41) pCmdUI->SetCheck(true);
806 else pCmdUI->SetCheck(false);
807}
808
809void CGeometryDoc::OnUpdateBUTTONTest42(CCmdUI* pCmdUI)
810{ if (Current == 42) pCmdUI->SetCheck(true);
811 else pCmdUI->SetCheck(false);
812}
813
814void CGeometryDoc::OnUpdateBUTTONTest43(CCmdUI* pCmdUI)
815{ if (Current == 43) pCmdUI->SetCheck(true);
816 else pCmdUI->SetCheck(false);
817}
818
819void CGeometryDoc::OnUpdateBUTTONTest44(CCmdUI* pCmdUI)
820{ if (Current == 44) pCmdUI->SetCheck(true);
821 else pCmdUI->SetCheck(false);
822}
823
824void CGeometryDoc::OnUpdateBUTTONTest45(CCmdUI* pCmdUI)
825{ if (Current == 45) pCmdUI->SetCheck(true);
826 else pCmdUI->SetCheck(false);
827}
828
829void CGeometryDoc::OnUpdateBUTTONTest46(CCmdUI* pCmdUI)
830{ if (Current == 46) pCmdUI->SetCheck(true);
831 else pCmdUI->SetCheck(false);
832}
833
834void CGeometryDoc::OnUpdateBUTTONTest47(CCmdUI* pCmdUI)
835{ if (Current == 47) pCmdUI->SetCheck(true);
836 else pCmdUI->SetCheck(false);
837}
838
839void CGeometryDoc::OnUpdateBUTTONTest48(CCmdUI* pCmdUI)
840{ if (Current == 48) pCmdUI->SetCheck(true);
841 else pCmdUI->SetCheck(false);
842}
843
844void CGeometryDoc::OnUpdateBUTTONTest49(CCmdUI* pCmdUI)
845{ if (Current == 49) pCmdUI->SetCheck(true);
846 else pCmdUI->SetCheck(false);
847}
848
849void CGeometryDoc::OnUpdateBUTTONTest50(CCmdUI* pCmdUI)
850{ if (Current == 50) pCmdUI->SetCheck(true);
851 else pCmdUI->SetCheck(false);
852}
853
854
855
856
857
858void CGeometryDoc::OnCloseDocument()
859{
860 // TODO: Add your specialized code here and/or call the base class
861
862 CDocument::OnCloseDocument();
863}
864
865void CGeometryDoc::Fit()
866{
867 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
868 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
869 OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView();
870 pView->FitAll();
871}
872
873
874void CGeometryDoc::OnCreateSol()
875{
876 // TODO: Add your command handler code here
877 // Creation d'un sol
878 CFileDialog dlg(TRUE,
879 NULL,
880 NULL,
881 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
882 "Points Files (*.dat)|*.dat; |All Files (*.*)|*.*||",
883 NULL );
884
885 CString initdir(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
886 initdir += "\\Data\\SurfaceFromPoints";
887
888 dlg.m_ofn.lpstrInitialDir = initdir;
889
890 if (dlg.DoModal() == IDOK)
891 {
892 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
893 CString filename = dlg.GetPathName();
894
895 filebuf fic;
896 istream in(&fic);
897 if (!fic.open((Standard_CString)(LPCTSTR)filename,ios::in))
898 MessageBox(AfxGetApp()->m_pMainWnd->m_hWnd,"Error : Unable to open file","CasCade Error",MB_ICONERROR);
899 TColgp_SequenceOfXYZ seqOfXYZ;
900 gp_XYZ pntXYZ;
901 Standard_Integer nbPnt=0;
902 Standard_Real x,y,z;
903 BRep_Builder B;
904 TopoDS_Compound C;
905 B.MakeCompound(C);
906 while (!in.fail()|| !in.eof()){
907 if (in >> x && in >> y && in >> z){
908 pntXYZ.SetX(x);
909 pntXYZ.SetY(y);
910 pntXYZ.SetZ(z);
911 nbPnt++;
912 seqOfXYZ.Append(pntXYZ);
913 BRepBuilderAPI_MakeVertex V(gp_Pnt(x, y, z));
914 B.Add(C,V.Vertex());
915 }
916 }
917 fic.close();
918 Handle(AIS_Shape) anAISCompound = new AIS_Shape(C);
919 myAISContext->Display(anAISCompound, Standard_False);
920 Fit();
921 Sleep(1000);
922 GeoAlgo_Sol sol;
923 sol.Build(seqOfXYZ);
924
925 if (sol.IsDone() == Standard_True){
926 Handle(Geom_BSplineSurface) GeomSol = sol.Surface();
9181b66d 927 TopoDS_Face aface = BRepBuilderAPI_MakeFace(GeomSol, Precision::Confusion());
7fd59977 928 if (!BRepAlgo::IsValid(aface))
929 MessageBox(AfxGetApp()->m_pMainWnd->m_hWnd,"Error : The plate surface is not valid!","CasCade Error",MB_ICONERROR);
930 Handle_AIS_Shape anAISShape=new AIS_Shape(aface);
931 myAISContext->Display(anAISShape, Standard_False);
932 Fit();
933 }
934 else
935 MessageBox(AfxGetApp()->m_pMainWnd->m_hWnd,"Error : Computation has failed","CasCade Error",MB_ICONERROR);
936 }
937}
938
939/*********************************************************************************************
940********************** S I M P L I F Y *****************************************************
941*********************************************************************************************/
942
943//================================================================
944// Function : fixParam
945// Purpose : assings a finite value to theParam if it intinite
946// (equal to +- Precision::Infinite())
947//================================================================
948static Standard_Boolean fixParam(Standard_Real& theParam)
949{
950 Standard_Boolean aResult = Standard_False;
951 if (Precision::IsNegativeInfinite(theParam))
952 {
953 theParam = -MAX_PARAM;
954 aResult = Standard_True;
955 }
956 if (Precision::IsPositiveInfinite(theParam))
957 {
958 theParam = MAX_PARAM;
959 aResult = Standard_True;
960 }
961 return aResult;
962}
963
964
965void CGeometryDoc::OnSimplify()
966{
967 CString initfile(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
968 initfile += "\\..\\..\\Data\\";
969 initfile += "shell1.brep";
970
971 TCollection_AsciiString Path((Standard_CString)(LPCTSTR)initfile);
972
973 TopoDS_Shape aShape;
974 BRep_Builder aBld;
975 //Standard_Boolean isRead = BRepTools::Read (aShape, aPath.ToCString(), aBld);
976 //if (!isRead)
977// isRead = BRepTools::Read (aShape, bPath.ToCString(), aBld);
978 Standard_Boolean isRead = BRepTools::Read (aShape, Path.ToCString(), aBld);
979 if (!isRead)
980 {
981 Path += " was not found. The sample can not be shown.";
982 myCResultDialog.SetText((CString)Path.ToCString());
983 return;
984 }
985
986 myAISContext->SetDisplayMode(AIS_Shaded);
987
988 simplify(aShape);
989}
990
991void CGeometryDoc::simplify(const TopoDS_Shape& aShape)
992{
993 myCResultDialog.SetTitle(CString("Simplify Face"));
994 myCResultDialog.SetText((CString)
995 " TopoDS_Shape aShape;" EOL
996 "" EOL
997 " // initialize aShape" EOL
998 " //aShape = ..." EOL
999 "" EOL
1000 " // define parameter triangulation" EOL
1001 " Standard_Real aDeflection = 0.1;" EOL
1002 " " EOL
1003 " // removes all the triangulations of the faces ," EOL
1004 " //and all the polygons on the triangulations of the edges" EOL
1005 " BRepTools::Clean(aShape);" EOL
1006 " // adds a triangulation of the shape aShape with the deflection aDeflection" EOL
1007 " BRepMesh::Mesh(aShape,aDeflection);" EOL
1008 "" EOL
1009 " Standard_Integer aIndex = 1, nbNodes = 0;" EOL
1010 " " EOL
1011 " // define two sequence of points" EOL
1012 " TColgp_SequenceOfPnt aPoints, aPoints1;" EOL
1013 " " EOL
1014 " // triangulation" EOL
1015 " for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())" EOL
1016 " { " EOL
1017 " TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());" EOL
1018 " TopLoc_Location aLocation;" EOL
1019 "" EOL
1020 " // takes the triangulation of the face aFace" EOL
1021 " Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);" EOL
1022 "" EOL
1023 " if(!aTr.IsNull())" EOL
1024 " { " EOL
1025 " // takes the array of nodes for this triangulation" EOL
1026 " const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); " EOL
1027 " nbNodes = aNodes.Length();" EOL
1028 "" EOL
1029 " for( Standard_Integer i = 1; i <= nbNodes; i++)" EOL
1030 " {" EOL
1031 " // create seguence of node points in absolute coordinate system" EOL
1032 " gp_Pnt aPnt = aNodes(i).Transformed(aLocation);" EOL
1033 " aPoints.Append(aPnt);" EOL
1034 " " EOL
1035 " }" EOL
1036 " }" EOL
1037 " }" EOL
1038 " " EOL
1039 " // remove double points" EOL
1040 " nbNodes = aPoints.Length();" EOL
1041 " for( Standard_Integer i = 1; i <= nbNodes; i++)" EOL
1042 " {" EOL
1043 " gp_Pnt aPi = aPoints(i);" EOL
1044 " for( Standard_Integer j = i + 1; j < nbNodes; j++)" EOL
1045 " {" EOL
1046 " gp_Pnt aPj = aPoints(j);" EOL
1047 " if(!aPi.IsEqual(aPj,0.9))" EOL
1048 " aIndex++;" EOL
1049 " }" EOL
1050 " if(aIndex == j - 1)" EOL
1051 " aPoints1.Append(aPi);" EOL
1052 "" EOL
1053 " aIndex = i + 1;" EOL
1054 " }" EOL
1055 "" EOL
1056 " // find max point" EOL
1057 " aIndex = 0;" EOL
1058 " gp_Pnt aPntMax = aPoints1(1);" EOL
1059 " nbNodes = aPoints1.Length();" EOL
1060 " for(i = 2; i <= nbNodes; i++)" EOL
1061 " {" EOL
1062 " if(aPoints1(i).X() > aPntMax.X())" EOL
1063 " {" EOL
1064 " aIndex = i;" EOL
1065 " aPntMax = aPoints1(aIndex); " EOL
1066 " } " EOL
1067 " }" EOL
1068 "" EOL
1069 " // clear seguence" EOL
1070 " aPoints.Clear();" EOL
1071 "" EOL
1072 " Standard_Integer nbLeftNodes = nbNodes;" EOL
1073 "" EOL
1074 " // ascending sort - fill aPoints with ascending " EOL
1075 " // by X coordinate points from aPoints1" EOL
1076 " for(i = 1; i < nbNodes; i++)" EOL
1077 " {" EOL
1078 " Standard_Real aMin = aPntMax.X();" EOL
1079 " aIndex = 1;" EOL
1080 " for( Standard_Integer j = 1; j <= nbLeftNodes; j++)" EOL
1081 " {" EOL
1082 " if(aPoints1(j).X() < aMin)" EOL
1083 " {" EOL
1084 " aMin = aPoints1(j).X();" EOL
1085 " aIndex = j;" EOL
1086 " } " EOL
1087 " }" EOL
1088 " aPoints.Append(aPoints1(aIndex));" EOL
1089 " aPoints1.Remove(aIndex);" EOL
1090 " nbLeftNodes = aPoints1.Length();" EOL
1091 " }" EOL
1092 " aPoints.Append(aPntMax);" EOL
1093 "" EOL
1094 " // define parameters GeomPlate_BuildPlateSurface" EOL
1095 " Standard_Integer Degree = 3;" EOL
1096 " Standard_Integer NbPtsOnCur = 10;" EOL
1097 " Standard_Integer NbIter = 3;" EOL
1098 " Standard_Integer Order = 0;" EOL
1099 " Standard_Integer MaxSeg = 9;" EOL
1100 " Standard_Integer MaxDegree = 5;" EOL
1101 " Standard_Real dmax, anApproxTol = 0.001;" EOL
1102 " Standard_Real aConstrTol = Precision::Confusion();" EOL
1103 " " EOL
1104 " // define object BuildPlateSurface" EOL
1105 " GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);" EOL
1106 " " EOL
1107 " // add point constraints to GeomPlate_BuildPlateSurface object" EOL
1108 " nbNodes = aPoints.Length();" EOL
1109 " for (i = 1; i <= nbNodes; i++)" EOL
1110 " BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));" EOL
1111 "" EOL
1112 " BPSurf.Perform();" EOL
1113 "" EOL
1114 " // make PlateSurface" EOL
1115 " Handle(GeomPlate_Surface) PSurf;" EOL
1116 " Handle(Geom_Surface) aSurf;" EOL
1117 " " EOL
1118 " if (BPSurf.IsDone())" EOL
1119 " {" EOL
1120 " PSurf = BPSurf.Surface();" EOL
1121 "" EOL
1122 " // define parameter approximation" EOL
1123 " dmax = Max(0.01,10*BPSurf.G0Error());" EOL
1124 "" EOL
1125 " // make approximation" EOL
1126 " GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);" EOL
1127 " aSurf = Mapp.Surface();" EOL
1128 " }" EOL
1129 " else " EOL
1130 " return;" EOL
1131 "" EOL
1132 " ShapeAnalysis_FreeBounds aFreeBounds(aShape, Standard_False, Standard_True);" EOL
1133 " TopoDS_Compound aClosedWires = aFreeBounds.GetClosedWires();" EOL
1134 " TopTools_IndexedMapOfShape aWires;" EOL
1135 " TopExp::MapShapes(aClosedWires, TopAbs_WIRE, aWires);" EOL
1136 " TopoDS_Wire aWire;" EOL
1137 " Standard_Integer nbWires = aWires.Extent();" EOL
1138 " if (nbWires) " EOL
1139 " aWire = TopoDS::Wire(aWires(1));" EOL
1140 " else " EOL
1141 " return;" EOL
1142 "" EOL
1143 " BRep_Builder B;" EOL
1144 " TopoDS_Face aFace;" EOL
1145 " B.MakeFace(aFace, aSurf, Precision::Confusion());" EOL
1146 " B.Add(aFace, aWire);" EOL
1147 " Handle_ShapeFix_Shape sfs = new ShapeFix_Shape(aFace);" EOL
1148 " sfs->Perform();" EOL
1149 " TopoDS_Shape aFixedFace = sfs->Shape();" EOL
1150 " if (aFixedFace.IsNull()) " EOL
1151 " return;" EOL);
1152
1153 // define parameter triangulation
1154 Standard_Real aDeflection = 0.1;
1155
1156 // removes all the triangulations of the faces ,
1157 //and all the polygons on the triangulations of the edges
1158 BRepTools::Clean(aShape);
1159 // adds a triangulation of the shape aShape with the deflection aDeflection
1160 BRepMesh::Mesh(aShape,aDeflection);
1161
1162 Standard_Integer aIndex = 1, nbNodes = 0;
1163
1164 // define two sequence of points
1165 TColgp_SequenceOfPnt aPoints, aPoints1;
1166
1167 // triangulation
1168 for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())
1169 {
1170 TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());
1171 TopLoc_Location aLocation;
1172
1173 // takes the triangulation of the face aFace
1174 Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);
1175
1176 if(!aTr.IsNull())
1177 {
1178 // takes the array of nodes for this triangulation
1179 const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
1180 nbNodes = aNodes.Length();
1181
1182 for( Standard_Integer i = 1; i <= nbNodes; i++)
1183 {
1184 // create seguence of node points in absolute coordinate system
1185 gp_Pnt aPnt = aNodes(i).Transformed(aLocation);
1186 aPoints.Append(aPnt);
1187
1188 }
1189 }
1190 }
1191
1192 // remove double points
1193 nbNodes = aPoints.Length();
1194 Standard_Integer i;
1195 for( i = 1; i <= nbNodes; i++)
1196 {
1197 gp_Pnt aPi = aPoints(i);
1198 Standard_Integer j;
1199 for( j = i + 1; j < nbNodes; j++)
1200 {
1201 gp_Pnt aPj = aPoints(j);
1202 if(!aPi.IsEqual(aPj,0.9))
1203 aIndex++;
1204 }
1205 if(aIndex == j - 1)
1206 aPoints1.Append(aPi);
1207
1208 aIndex = i + 1;
1209 }
1210
1211 // find max point
1212 aIndex = 0;
1213 gp_Pnt aPntMax = aPoints1(1);
1214 nbNodes = aPoints1.Length();
1215 for(i = 2; i <= nbNodes; i++)
1216 {
1217 if(aPoints1(i).X() > aPntMax.X())
1218 {
1219 aIndex = i;
1220 aPntMax = aPoints1(aIndex);
1221 }
1222 }
1223
1224 // clear seguence
1225 aPoints.Clear();
1226
1227 Standard_Integer nbLeftNodes = nbNodes;
1228
1229 // ascending sort - fill aPoints with ascending
1230 // by X coordinate points from aPoints1
1231 for(i = 1; i < nbNodes; i++)
1232 {
1233 Standard_Real aMin = aPntMax.X();
1234 aIndex = 1;
1235 for( Standard_Integer j = 1; j <= nbLeftNodes; j++)
1236 {
1237 if(aPoints1(j).X() < aMin)
1238 {
1239 aMin = aPoints1(j).X();
1240 aIndex = j;
1241 }
1242 }
1243 aPoints.Append(aPoints1(aIndex));
1244 aPoints1.Remove(aIndex);
1245 nbLeftNodes = aPoints1.Length();
1246 }
1247 aPoints.Append(aPntMax);
1248
1249 // define parameters GeomPlate_BuildPlateSurface
1250 Standard_Integer Degree = 3;
1251 Standard_Integer NbPtsOnCur = 10;
1252 Standard_Integer NbIter = 3;
1253 Standard_Integer Order = 0;
1254 Standard_Integer MaxSeg = 9;
1255 Standard_Integer MaxDegree = 5;
1256 Standard_Real dmax, anApproxTol = 0.001;
1257 Standard_Real aConstrTol = Precision::Confusion();
1258
1259 // define object BuildPlateSurface
1260 GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);
1261
1262 // add point constraints to GeomPlate_BuildPlateSurface object
1263 nbNodes = aPoints.Length();
1264 for (i = 1; i <= nbNodes; i++)
1265 BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));
1266
1267 BPSurf.Perform();
1268
1269 // make PlateSurface
1270 Handle(GeomPlate_Surface) PSurf;
1271 Handle(Geom_Surface) aSurf;
1272
1273 if (BPSurf.IsDone())
1274 {
1275 PSurf = BPSurf.Surface();
1276
1277 // define parameter approximation
1278 dmax = Max(0.01,10*BPSurf.G0Error());
1279
1280 // make approximation
1281 GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);
1282 aSurf = Mapp.Surface();
1283 }
1284 else
1285 return;
1286
1287 ShapeAnalysis_FreeBounds aFreeBounds(aShape, Standard_False, Standard_True);
1288 TopoDS_Compound aClosedWires = aFreeBounds.GetClosedWires();
1289 TopTools_IndexedMapOfShape aWires;
1290 TopExp::MapShapes(aClosedWires, TopAbs_WIRE, aWires);
1291 TopoDS_Wire aWire;
1292 Standard_Integer nbWires = aWires.Extent();
1293 if (nbWires)
1294 aWire = TopoDS::Wire(aWires(1));
1295 else
1296 return;
1297
1298 BRep_Builder B;
1299 TopoDS_Face aFace;
1300 B.MakeFace(aFace, aSurf, Precision::Confusion());
1301 B.Add(aFace, aWire);
1302 Handle_ShapeFix_Shape sfs = new ShapeFix_Shape(aFace);
1303 sfs->Perform();
1304 TopoDS_Shape aFixedFace = sfs->Shape();
1305 if (aFixedFace.IsNull())
1306 return;
1307
1308 // output surface, make it half transparent
1309 Handle_AIS_InteractiveObject aSurfIO = drawSurface(
1310 aSurf, Quantity_NOC_LEMONCHIFFON3, Standard_False);
1311 aSurfIO->SetTransparency(0.5);
1312 myAISContext->Display(aSurfIO,Standard_False);
1313 Fit();
1314
1315 if(WAIT_A_LITTLE) return;
1316
1317 // output points
1318 for(i = 1; i <= nbNodes; i++)
1319 drawPoint(aPoints(i));
1320
1321 if(WAIT_A_LITTLE) return;
1322
1323 // output resulting face
1324 drawShape(aFixedFace);
1325}
1326
1327Handle_AIS_InteractiveObject CGeometryDoc::drawSurface
1328 (const Handle_Geom_Surface& theSurface,
1329 const Quantity_Color& theColor,
1330 const Standard_Boolean toDisplay)
1331{
1332 Standard_Real u1, u2, v1, v2;
1333 theSurface->Bounds(u1,u2,v1,v2);
1334 fixParam(u1);
1335 fixParam(u2);
1336 fixParam(v1);
1337 fixParam(v2);
1338
1339 Handle_AIS_Shape aGraphicSurface =
9181b66d 1340 new AIS_Shape(BRepBuilderAPI_MakeFace (theSurface, u1, u2, v1, v2, Precision::Confusion()));
7fd59977 1341
1342 myAISContext->SetMaterial(aGraphicSurface, Graphic3d_NOM_PLASTIC, toDisplay);
1343 myAISContext->SetColor(aGraphicSurface, theColor, toDisplay);
1344 if (toDisplay) {
1345 if (FitMode){
1346 myAISContext->Display (aGraphicSurface, Standard_False);
1347 Fit();
1348 }
1349 else
1350 myAISContext->Display (aGraphicSurface);
1351 }
1352
1353 return aGraphicSurface;
1354}
1355
1356Standard_Boolean CGeometryDoc::WaitForInput (unsigned long aMilliSeconds)
1357{
1358 //::WaitForSingleObject(::CreateEvent (NULL, FALSE, FALSE, NULL), aMilliSeconds);
1359 if (::MsgWaitForMultipleObjects(0, NULL, FALSE, aMilliSeconds,
1360 QS_KEY | QS_MOUSEBUTTON) != WAIT_TIMEOUT)
1361 {
1362 MSG msg;
1363 if (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
1364 {
1365 if (msg.message == WM_KEYUP)
1366 {
1367 ::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE);
1368 return WaitForInput (aMilliSeconds);
1369 }
1370 else
1371 return Standard_True;
1372 }
1373 }
1374 return Standard_False;
1375}
1376
1377Handle_AIS_Point CGeometryDoc::drawPoint
1378 (const gp_Pnt& aPnt,
1379 const Quantity_Color& theColor,
1380 const Standard_Boolean toDisplay)
1381{
1382 Handle(AIS_Point) aGraphicPoint = new AIS_Point (new Geom_CartesianPoint(aPnt));
1383
1384 myAISContext->SetColor (aGraphicPoint, theColor, toDisplay);
1385 if (toDisplay) {
1386 myAISContext->Display (aGraphicPoint);
1387 //COCCDemoDoc::Fit();
1388 }
1389
1390 return aGraphicPoint;
1391}
1392
1393Handle_AIS_Shape CGeometryDoc::drawShape
1394 (const TopoDS_Shape& theShape,
1395 const Graphic3d_NameOfMaterial theMaterial,
1396 const Standard_Boolean toDisplay)
1397{
1398 Handle_AIS_Shape aGraphicShape = new AIS_Shape(theShape);
1399
1400 myAISContext->SetMaterial(aGraphicShape, theMaterial, toDisplay);
1401 if (toDisplay) {
1402 if (FitMode){
1403 myAISContext->Display (aGraphicShape, Standard_False);
1404 Fit();
1405 }
1406 else
1407 myAISContext->Display (aGraphicShape);
1408 }
1409
1410 return aGraphicShape;
1411}