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