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