1 // GeometryDoc.cpp : implementation of the CGeometryDoc class
6 #include "GeometryDoc.h"
7 #include "GeoAlgo_Sol.hxx"
8 #include "GeometryApp.h"
9 #include "GeometryView2D.h"
10 #include "GeometryView.h"
14 static char THIS_FILE[] = __FILE__;
16 #include "GeomSources.h"
20 #define WAIT_A_LITTLE WaitForInput(500)
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.
25 /////////////////////////////////////////////////////////////////////////////
28 IMPLEMENT_DYNCREATE(CGeometryDoc, OCC_3dBaseDoc)
30 BEGIN_MESSAGE_MAP(CGeometryDoc, OCC_3dBaseDoc)
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)
138 /////////////////////////////////////////////////////////////////////////////
139 // CGeometryDoc construction/destruction
141 CGeometryDoc::CGeometryDoc()
147 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(11);
148 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(11);
150 Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((OCC_App*)AfxGetApp())->GetGraphicDriver();
151 myViewer2D = new V3d_Viewer (aGraphicDriver);
152 myViewer2D->SetCircularGridValues(0,0,1,8,0);
153 myViewer2D->SetRectangularGridValues(0,0,1,1,0);
155 // Set view projection
156 myViewer2D->SetDefaultViewProj(V3d_Zpos);
157 myAISContext2D = new AIS_InteractiveContext(myViewer2D);
158 myCResultDialog.Create(CResultDialog::IDD,NULL);
161 myCResultDialog.GetWindowRect(&dlgrect);
162 LONG width = dlgrect.right-dlgrect.left;
163 LONG height = dlgrect.bottom-dlgrect.top;
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);
170 ((CGeometryApp*)AfxGetApp())->CreateView2D(this);
175 CGeometryDoc::~CGeometryDoc()
179 BOOL CGeometryDoc::OnNewDocument()
181 if (!CDocument::OnNewDocument())
184 // TODO: add reinitialization code here
185 // (SDI documents will reuse this document)
186 // compute a graphic device --> the same for all Views
191 void CGeometryDoc::OnWindowNew2d()
193 ((CGeometryApp*)AfxGetApp())->CreateView2D(this);
196 /////////////////////////////////////////////////////////////////////////////
197 // CGeometryDoc serialization
199 void CGeometryDoc::Serialize(CArchive& ar)
203 // TODO: add storing code here
207 // TODO: add loading code here
211 /////////////////////////////////////////////////////////////////////////////
212 // CGeometryDoc diagnostics
215 void CGeometryDoc::AssertValid() const
217 CDocument::AssertValid();
220 void CGeometryDoc::Dump(CDumpContext& dc) const
226 /////////////////////////////////////////////////////////////////////////////
227 // CGeometryDoc commands
229 //-----------------------------------------------------------------------------------------
231 //-----------------------------------------------------------------------------------------
232 void CGeometryDoc::DragEvent2D(const Standard_Integer /*x*/,
233 const Standard_Integer /*y*/,
234 const Standard_Integer /*TheState*/,
235 const Handle(V3d_View)& /*aView*/)
240 //-----------------------------------------------------------------------------------------
242 //-----------------------------------------------------------------------------------------
243 void CGeometryDoc::InputEvent2D(const Standard_Integer /*x*/,
244 const Standard_Integer /*y*/,
245 const Handle(V3d_View)& /*aView*/)
247 myAISContext2D->Select(Standard_True);
250 //-----------------------------------------------------------------------------------------
252 //-----------------------------------------------------------------------------------------
253 void CGeometryDoc::MoveEvent2D(const Standard_Integer x,
254 const Standard_Integer y,
255 const Handle(V3d_View)& aView)
257 if(aView->Viewer()->Grid()->IsActive())
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
264 this->myAISContext2D->MoveTo (x, y, aView, Standard_True);
267 //-----------------------------------------------------------------------------------------
269 //-----------------------------------------------------------------------------------------
270 void CGeometryDoc::ShiftMoveEvent2D(const Standard_Integer /*x*/,
271 const Standard_Integer /*y*/,
272 const Handle(V3d_View)& /*aView*/)
276 //-----------------------------------------------------------------------------------------
278 //-----------------------------------------------------------------------------------------
279 void CGeometryDoc::ShiftDragEvent2D(const Standard_Integer /*x*/,
280 const Standard_Integer /*y*/,
281 const Standard_Integer /*TheState*/,
282 const Handle(V3d_View)& /*aView*/)
287 //-----------------------------------------------------------------------------------------
289 //-----------------------------------------------------------------------------------------
290 void CGeometryDoc::ShiftInputEvent2D(const Standard_Integer /*x*/,
291 const Standard_Integer /*y*/,
292 const Handle(V3d_View)& /*aView*/)
296 //-----------------------------------------------------------------------------------------
298 //-----------------------------------------------------------------------------------------
299 void CGeometryDoc::Popup2D(const Standard_Integer x,
300 const Standard_Integer y,
301 const Handle(V3d_View)& aView)
304 VERIFY(menu.LoadMenu(IDR_Popup3D));
307 pPopup = menu.GetSubMenu(0);
309 ASSERT(pPopup != NULL);
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 ,
320 //-----------------------------------------------------------------------------------------
322 //-----------------------------------------------------------------------------------------
323 void CGeometryDoc::Popup (const Standard_Integer theMouseX,
324 const Standard_Integer theMouseY,
325 const Handle(V3d_View)& theView)
327 Standard_Integer PopupMenuNumber=0;
328 GetAISContext()->InitSelected();
329 if (GetAISContext()->MoreSelected())
335 VERIFY(menu.LoadMenu(IDR_Popup3D));
336 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
337 ASSERT(pPopup != NULL);
339 POINT winCoord = { theMouseX , theMouseY };
340 Handle(WNT_Window) aWNTWindow = Handle(WNT_Window)::DownCast(theView->Window());
341 ClientToScreen ( (HWND)(aWNTWindow->HWindow()), &winCoord );
343 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON ,
344 winCoord.x, winCoord.y ,
348 //-----------------------------------------------------------------------------------------
350 //-----------------------------------------------------------------------------------------
351 void CGeometryDoc::InputEvent (const Standard_Integer /*theMouseX*/,
352 const Standard_Integer /*theMouseY*/,
353 const Handle(V3d_View)& /*theView*/)
355 myAISContext->Select (Standard_True);
358 //-----------------------------------------------------------------------------------------
360 //-----------------------------------------------------------------------------------------
361 void CGeometryDoc::Put2DOnTop(bool isMax)
363 POSITION position = GetFirstViewPosition();
364 while (position != (POSITION)NULL)
366 CView* pCurrentView = (CView*)GetNextView(position);
367 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
369 ASSERT_VALID(pCurrentView);
370 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
371 ASSERT(pParentFrm != (CFrameWnd *)NULL);
372 // simply make the frame window visible
375 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
379 pParentFrm->ActivateFrame(SW_SHOW);
385 //-----------------------------------------------------------------------------------------
387 //-----------------------------------------------------------------------------------------
388 void CGeometryDoc::Minimize2D()
390 POSITION position = GetFirstViewPosition();
391 while (position != (POSITION)NULL)
393 CView* pCurrentView = (CView*)GetNextView(position);
394 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
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);
405 //-----------------------------------------------------------------------------------------
407 //-----------------------------------------------------------------------------------------
408 void CGeometryDoc::Fit2DViews()
410 POSITION position = GetFirstViewPosition();
411 while (position != (POSITION)NULL)
413 CView* pCurrentView = (CView*)GetNextView(position);
414 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
416 ASSERT_VALID(pCurrentView);
417 CGeometryView2D* aCGeometryView2D = (CGeometryView2D*)pCurrentView;
418 aCGeometryView2D->FitAll();
423 //-----------------------------------------------------------------------------------------
425 //-----------------------------------------------------------------------------------------
426 void CGeometryDoc::Put3DOnTop(bool isMax)
428 POSITION position = GetFirstViewPosition();
429 while (position != (POSITION)NULL)
431 CView* pCurrentView = (CView*)GetNextView(position);
432 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
434 ASSERT_VALID(pCurrentView);
435 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
436 ASSERT(pParentFrm != (CFrameWnd *)NULL);
437 // simply make the frame window visible
440 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
444 pParentFrm->ActivateFrame(SW_SHOW);
450 //-----------------------------------------------------------------------------------------
452 //-----------------------------------------------------------------------------------------
453 void CGeometryDoc::Minimize3D()
455 POSITION position = GetFirstViewPosition();
456 while (position != (POSITION)NULL)
458 CView* pCurrentView = (CView*)GetNextView(position);
459 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
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);
470 //-----------------------------------------------------------------------------------------
472 //-----------------------------------------------------------------------------------------
473 void CGeometryDoc::Fit3DViews(Quantity_Coefficient Coef)
475 POSITION position = GetFirstViewPosition();
476 while (position != (POSITION)NULL)
478 CView* pCurrentView = (CView*)GetNextView(position);
479 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
481 ASSERT_VALID(pCurrentView);
482 CGeometryView* aCGeometryView = (CGeometryView*)pCurrentView;
483 aCGeometryView->FitAll(Coef);
488 //-----------------------------------------------------------------------------------------
490 //-----------------------------------------------------------------------------------------
491 void CGeometryDoc::Set3DViewsZoom(const Quantity_Factor& Coef)
493 POSITION position = GetFirstViewPosition();
494 while (position != (POSITION)NULL)
496 CView* pCurrentView = (CView*)GetNextView(position);
497 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
499 ASSERT_VALID(pCurrentView);
500 CGeometryView* aCGeometryView = (CGeometryView*)pCurrentView;
501 aCGeometryView->SetZoom( Coef );
506 //-----------------------------------------------------------------------------------------
507 // Buttons event handlers
508 //-----------------------------------------------------------------------------------------
509 void CGeometryDoc::OnBUTTONTest1()
511 GeomSources::gpTest1(this); }
512 void CGeometryDoc::OnBUTTONTest2()
514 GeomSources::gpTest2(this); }
515 void CGeometryDoc::OnBUTTONTest3()
517 GeomSources::gpTest3(this); }
518 void CGeometryDoc::OnBUTTONTest4()
520 GeomSources::gpTest4(this); }
521 void CGeometryDoc::OnBUTTONTest5()
523 GeomSources::gpTest5(this); }
524 void CGeometryDoc::OnBUTTONTest6()
526 GeomSources::gpTest6(this); }
527 void CGeometryDoc::OnBUTTONTest7()
529 GeomSources::gpTest7(this); }
530 void CGeometryDoc::OnBUTTONTest8()
532 GeomSources::gpTest8(this); }
533 void CGeometryDoc::OnBUTTONTest9()
535 GeomSources::gpTest9(this); }
536 void CGeometryDoc::OnBUTTONTest10()
538 GeomSources::gpTest10(this); }
539 void CGeometryDoc::OnBUTTONTest11()
541 GeomSources::gpTest11(this); }
542 void CGeometryDoc::OnBUTTONTest12()
544 GeomSources::gpTest12(this); }
545 void CGeometryDoc::OnBUTTONTest13()
547 GeomSources::gpTest13(this); }
548 void CGeometryDoc::OnBUTTONTest14()
550 GeomSources::gpTest14(this); }
551 void CGeometryDoc::OnBUTTONTest15()
553 GeomSources::gpTest15(this); }
554 void CGeometryDoc::OnBUTTONTest16()
556 GeomSources::gpTest16(this); }
557 void CGeometryDoc::OnBUTTONTest17()
559 GeomSources::gpTest17(this); }
560 void CGeometryDoc::OnBUTTONTest18()
562 GeomSources::gpTest18(this); }
563 void CGeometryDoc::OnBUTTONTest19()
565 GeomSources::gpTest19(this); }
566 void CGeometryDoc::OnBUTTONTest20()
568 GeomSources::gpTest20(this); }
569 void CGeometryDoc::OnBUTTONTest21()
571 GeomSources::gpTest21(this); }
572 void CGeometryDoc::OnBUTTONTest22()
574 GeomSources::gpTest22(this); }
575 void CGeometryDoc::OnBUTTONTest23()
577 GeomSources::gpTest23(this); }
578 void CGeometryDoc::OnBUTTONTest24()
580 GeomSources::gpTest24(this); }
581 void CGeometryDoc::OnBUTTONTest25()
583 GeomSources::gpTest25(this); }
584 void CGeometryDoc::OnBUTTONTest26()
586 GeomSources::gpTest26(this); }
587 void CGeometryDoc::OnBUTTONTest27()
589 GeomSources::gpTest27(this); }
590 void CGeometryDoc::OnBUTTONTest28()
592 GeomSources::gpTest28(this); }
593 void CGeometryDoc::OnBUTTONTest29()
595 GeomSources::gpTest29(this); }
596 void CGeometryDoc::OnBUTTONTest30()
598 GeomSources::gpTest30(this); }
599 void CGeometryDoc::OnBUTTONTest31()
601 GeomSources::gpTest31(this); }
602 void CGeometryDoc::OnBUTTONTest32()
604 GeomSources::gpTest32(this); }
605 void CGeometryDoc::OnBUTTONTest33()
607 GeomSources::gpTest33(this); }
608 void CGeometryDoc::OnBUTTONTest34()
610 GeomSources::gpTest34(this); }
611 void CGeometryDoc::OnBUTTONTest35()
613 GeomSources::gpTest35(this); }
614 void CGeometryDoc::OnBUTTONTest36()
616 GeomSources::gpTest36(this); }
618 void CGeometryDoc::OnBUTTONTest37()
620 GeomSources::gpTest37(this); }
621 void CGeometryDoc::OnBUTTONTest38()
623 GeomSources::gpTest38(this); }
624 void CGeometryDoc::OnBUTTONTest39()
626 GeomSources::gpTest39(this); }
627 void CGeometryDoc::OnBUTTONTest40()
629 GeomSources::gpTest40(this); }
630 void CGeometryDoc::OnBUTTONTest41()
632 GeomSources::gpTest41(this); }
633 void CGeometryDoc::OnBUTTONTest42()
635 GeomSources::gpTest42(this); }
636 void CGeometryDoc::OnBUTTONTest43()
638 GeomSources::gpTest43(this); }
639 void CGeometryDoc::OnBUTTONTest44()
641 GeomSources::gpTest44(this); }
642 void CGeometryDoc::OnBUTTONTest45()
644 GeomSources::gpTest45(this); }
645 void CGeometryDoc::OnBUTTONTest46()
647 GeomSources::gpTest46(this); }
648 void CGeometryDoc::OnBUTTONTest47()
650 GeomSources::gpTest47(this); }
651 void CGeometryDoc::OnBUTTONTest48()
653 GeomSources::gpTest48(this); }
654 void CGeometryDoc::OnBUTTONTest49()
656 GeomSources::gpTest49(this); }
657 void CGeometryDoc::OnBUTTONTest50()
659 GeomSources::gpTest50(this); }
661 void CGeometryDoc::OnUpdateBUTTONTest1(CCmdUI* pCmdUI)
664 pCmdUI->SetCheck(true);
666 pCmdUI->SetCheck(false);
669 void CGeometryDoc::OnUpdateBUTTONTest2(CCmdUI* pCmdUI)
672 pCmdUI->SetCheck(true);
674 pCmdUI->SetCheck(false);
677 void CGeometryDoc::OnUpdateBUTTONTest3(CCmdUI* pCmdUI)
680 pCmdUI->SetCheck(true);
682 pCmdUI->SetCheck(false);
685 void CGeometryDoc::OnUpdateBUTTONTest4(CCmdUI* pCmdUI)
688 pCmdUI->SetCheck(true);
690 pCmdUI->SetCheck(false);
693 void CGeometryDoc::OnUpdateBUTTONTest5(CCmdUI* pCmdUI)
696 pCmdUI->SetCheck(true);
698 pCmdUI->SetCheck(false);
701 void CGeometryDoc::OnUpdateBUTTONTest6(CCmdUI* pCmdUI)
704 pCmdUI->SetCheck(true);
706 pCmdUI->SetCheck(false);
709 void CGeometryDoc::OnUpdateBUTTONTest7(CCmdUI* pCmdUI)
712 pCmdUI->SetCheck(true);
714 pCmdUI->SetCheck(false);
717 void CGeometryDoc::OnUpdateBUTTONTest8(CCmdUI* pCmdUI)
720 pCmdUI->SetCheck(true);
722 pCmdUI->SetCheck(false);
725 void CGeometryDoc::OnUpdateBUTTONTest9(CCmdUI* pCmdUI)
728 pCmdUI->SetCheck(true);
730 pCmdUI->SetCheck(false);
733 void CGeometryDoc::OnUpdateBUTTONTest10(CCmdUI* pCmdUI)
736 pCmdUI->SetCheck(true);
738 pCmdUI->SetCheck(false);
741 void CGeometryDoc::OnUpdateBUTTONTest11(CCmdUI* pCmdUI)
744 pCmdUI->SetCheck(true);
746 pCmdUI->SetCheck(false);
749 void CGeometryDoc::OnUpdateBUTTONTest12(CCmdUI* pCmdUI)
752 pCmdUI->SetCheck(true);
753 else pCmdUI->SetCheck(false);
756 void CGeometryDoc::OnUpdateBUTTONTest13(CCmdUI* pCmdUI)
759 pCmdUI->SetCheck(true);
761 pCmdUI->SetCheck(false);
764 void CGeometryDoc::OnUpdateBUTTONTest14(CCmdUI* pCmdUI)
767 pCmdUI->SetCheck(true);
769 pCmdUI->SetCheck(false);
772 void CGeometryDoc::OnUpdateBUTTONTest15(CCmdUI* pCmdUI)
775 pCmdUI->SetCheck(true);
777 pCmdUI->SetCheck(false);
780 void CGeometryDoc::OnUpdateBUTTONTest16(CCmdUI* pCmdUI)
783 pCmdUI->SetCheck(true);
785 pCmdUI->SetCheck(false);
788 void CGeometryDoc::OnUpdateBUTTONTest17(CCmdUI* pCmdUI)
791 pCmdUI->SetCheck(true);
793 pCmdUI->SetCheck(false);
796 void CGeometryDoc::OnUpdateBUTTONTest18(CCmdUI* pCmdUI)
799 pCmdUI->SetCheck(true);
801 pCmdUI->SetCheck(false);
804 void CGeometryDoc::OnUpdateBUTTONTest19(CCmdUI* pCmdUI)
807 pCmdUI->SetCheck(true);
809 pCmdUI->SetCheck(false);
812 void CGeometryDoc::OnUpdateBUTTONTest20(CCmdUI* pCmdUI)
815 pCmdUI->SetCheck(true);
817 pCmdUI->SetCheck(false);
820 void CGeometryDoc::OnUpdateBUTTONTest21(CCmdUI* pCmdUI)
823 pCmdUI->SetCheck(true);
825 pCmdUI->SetCheck(false);
828 void CGeometryDoc::OnUpdateBUTTONTest22(CCmdUI* pCmdUI)
831 pCmdUI->SetCheck(true);
833 pCmdUI->SetCheck(false);
836 void CGeometryDoc::OnUpdateBUTTONTest23(CCmdUI* pCmdUI)
839 pCmdUI->SetCheck(true);
841 pCmdUI->SetCheck(false);
844 void CGeometryDoc::OnUpdateBUTTONTest24(CCmdUI* pCmdUI)
847 pCmdUI->SetCheck(true);
849 pCmdUI->SetCheck(false);
852 void CGeometryDoc::OnUpdateBUTTONTest25(CCmdUI* pCmdUI)
855 pCmdUI->SetCheck(true);
857 pCmdUI->SetCheck(false);
860 void CGeometryDoc::OnUpdateBUTTONTest26(CCmdUI* pCmdUI)
863 pCmdUI->SetCheck(true);
865 pCmdUI->SetCheck(false);
868 void CGeometryDoc::OnUpdateBUTTONTest27(CCmdUI* pCmdUI)
871 pCmdUI->SetCheck(true);
873 pCmdUI->SetCheck(false);
876 void CGeometryDoc::OnUpdateBUTTONTest28(CCmdUI* pCmdUI)
879 pCmdUI->SetCheck(true);
881 pCmdUI->SetCheck(false);
884 void CGeometryDoc::OnUpdateBUTTONTest29(CCmdUI* pCmdUI)
887 pCmdUI->SetCheck(true);
889 pCmdUI->SetCheck(false);
892 void CGeometryDoc::OnUpdateBUTTONTest30(CCmdUI* pCmdUI)
895 pCmdUI->SetCheck(true);
897 pCmdUI->SetCheck(false);
900 void CGeometryDoc::OnUpdateBUTTONTest31(CCmdUI* pCmdUI)
903 pCmdUI->SetCheck(true);
905 pCmdUI->SetCheck(false);
908 void CGeometryDoc::OnUpdateBUTTONTest32(CCmdUI* pCmdUI)
911 pCmdUI->SetCheck(true);
913 pCmdUI->SetCheck(false);
916 void CGeometryDoc::OnUpdateBUTTONTest33(CCmdUI* pCmdUI)
919 pCmdUI->SetCheck(true);
921 pCmdUI->SetCheck(false);
924 void CGeometryDoc::OnUpdateBUTTONTest34(CCmdUI* pCmdUI)
927 pCmdUI->SetCheck(true);
929 pCmdUI->SetCheck(false);
932 void CGeometryDoc::OnUpdateBUTTONTest35(CCmdUI* pCmdUI)
935 pCmdUI->SetCheck(true);
937 pCmdUI->SetCheck(false);
940 void CGeometryDoc::OnUpdateBUTTONTest36(CCmdUI* pCmdUI)
943 pCmdUI->SetCheck(true);
945 pCmdUI->SetCheck(false);
948 void CGeometryDoc::OnUpdateBUTTONTest37(CCmdUI* pCmdUI)
951 pCmdUI->SetCheck(true);
953 pCmdUI->SetCheck(false);
956 void CGeometryDoc::OnUpdateBUTTONTest38(CCmdUI* pCmdUI)
959 pCmdUI->SetCheck(true);
961 pCmdUI->SetCheck(false);
964 void CGeometryDoc::OnUpdateBUTTONTest39(CCmdUI* pCmdUI)
967 pCmdUI->SetCheck(true);
969 pCmdUI->SetCheck(false);
972 void CGeometryDoc::OnUpdateBUTTONTest40(CCmdUI* pCmdUI)
975 pCmdUI->SetCheck(true);
977 pCmdUI->SetCheck(false);
980 void CGeometryDoc::OnUpdateBUTTONTest41(CCmdUI* pCmdUI)
983 pCmdUI->SetCheck(true);
985 pCmdUI->SetCheck(false);
988 void CGeometryDoc::OnUpdateBUTTONTest42(CCmdUI* pCmdUI)
991 pCmdUI->SetCheck(true);
993 pCmdUI->SetCheck(false);
996 void CGeometryDoc::OnUpdateBUTTONTest43(CCmdUI* pCmdUI)
999 pCmdUI->SetCheck(true);
1001 pCmdUI->SetCheck(false);
1004 void CGeometryDoc::OnUpdateBUTTONTest44(CCmdUI* pCmdUI)
1007 pCmdUI->SetCheck(true);
1009 pCmdUI->SetCheck(false);
1012 void CGeometryDoc::OnUpdateBUTTONTest45(CCmdUI* pCmdUI)
1015 pCmdUI->SetCheck(true);
1017 pCmdUI->SetCheck(false);
1020 void CGeometryDoc::OnUpdateBUTTONTest46(CCmdUI* pCmdUI)
1023 pCmdUI->SetCheck(true);
1025 pCmdUI->SetCheck(false);
1028 void CGeometryDoc::OnUpdateBUTTONTest47(CCmdUI* pCmdUI)
1031 pCmdUI->SetCheck(true);
1033 pCmdUI->SetCheck(false);
1036 void CGeometryDoc::OnUpdateBUTTONTest48(CCmdUI* pCmdUI)
1039 pCmdUI->SetCheck(true);
1041 pCmdUI->SetCheck(false);
1044 void CGeometryDoc::OnUpdateBUTTONTest49(CCmdUI* pCmdUI)
1047 pCmdUI->SetCheck(true);
1049 pCmdUI->SetCheck(false);
1052 void CGeometryDoc::OnUpdateBUTTONTest50(CCmdUI* pCmdUI)
1055 pCmdUI->SetCheck(true);
1057 pCmdUI->SetCheck(false);
1060 void CGeometryDoc::OnCloseDocument()
1062 // TODO: Add your specialized code here and/or call the base class
1063 CDocument::OnCloseDocument();
1066 void CGeometryDoc::OnCreateSol()
1068 // TODO: Add your command handler code here
1069 // Creation d'un sol
1070 CFileDialog dlg (TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
1071 L"Points Files (*.dat)|*.dat; |All Files (*.*)|*.*||", NULL);
1073 CString initdir(((OCC_App*) AfxGetApp())->GetInitDataDir());
1074 initdir += L"\\Data\\SurfaceFromPoints";
1076 dlg.m_ofn.lpstrInitialDir = initdir;
1078 if (dlg.DoModal() == IDOK)
1080 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
1081 CString filename = dlg.GetPathName();
1085 if (!fic.open (filename, ios::in))
1086 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Unable to open file", L"CasCade Error", MB_ICONERROR);
1088 TColgp_SequenceOfXYZ seqOfXYZ;
1090 Standard_Integer nbPnt=0;
1091 Standard_Real x,y,z;
1095 while (!in.fail()|| !in.eof())
1097 if (in >> x && in >> y && in >> z){
1102 seqOfXYZ.Append(pntXYZ);
1103 BRepBuilderAPI_MakeVertex V(gp_Pnt(x, y, z));
1104 B.Add(C,V.Vertex());
1108 Handle(AIS_Shape) anAISCompound = new AIS_Shape(C);
1109 myAISContext->Display(anAISCompound, Standard_False);
1113 sol.Build(seqOfXYZ);
1115 if (sol.IsDone() == Standard_True)
1117 Handle(Geom_BSplineSurface) GeomSol = sol.Surface();
1118 TopoDS_Face aface = BRepBuilderAPI_MakeFace(GeomSol, Precision::Confusion());
1119 if (!BRepAlgo::IsValid(aface))
1120 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : The plate surface is not valid!", L"CasCade Error", MB_ICONERROR);
1121 Handle(AIS_Shape) anAISShape=new AIS_Shape(aface);
1122 myAISContext->Display(anAISShape, Standard_False);
1126 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Computation has failed", L"CasCade Error", MB_ICONERROR);
1130 /*********************************************************************************************
1131 ********************** S I M P L I F Y *****************************************************
1132 *********************************************************************************************/
1134 //================================================================
1135 // Function : fixParam
1136 // Purpose : assings a finite value to theParam if it intinite
1137 // (equal to +- Precision::Infinite())
1138 //================================================================
1139 static Standard_Boolean fixParam(Standard_Real& theParam)
1141 Standard_Boolean aResult = Standard_False;
1142 if (Precision::IsNegativeInfinite(theParam))
1144 theParam = -MAX_PARAM;
1145 aResult = Standard_True;
1147 if (Precision::IsPositiveInfinite(theParam))
1149 theParam = MAX_PARAM;
1150 aResult = Standard_True;
1156 void CGeometryDoc::OnSimplify()
1158 CString initfile(((OCC_App*) AfxGetApp())->GetInitDataDir());
1159 initfile += L"\\..\\..\\..\\samples\\mfc\\standard\\01_Geometry\\Data\\";
1160 initfile += L"shell1.brep";
1162 std::filebuf aFileBuf;
1163 std::istream aStream (&aFileBuf);
1164 if (!aFileBuf.open (initfile, ios::in))
1166 initfile += L" was not found. The sample can not be shown.";
1167 myCResultDialog.SetText (initfile);
1171 TopoDS_Shape aShape;
1173 BRepTools::Read (aShape, aStream, aBld);
1174 if (aShape.IsNull())
1176 initfile += L" is invalid file. The sample can not be shown.";
1177 myCResultDialog.SetText(initfile);
1180 myAISContext->SetDisplayMode(AIS_Shaded, Standard_True);
1184 void CGeometryDoc::simplify(const TopoDS_Shape& aShape)
1186 myCResultDialog.SetTitle("Simplify Face");
1187 myCResultDialog.SetText(" TopoDS_Shape aShape;\n"
1189 " // initialize aShape\n"
1192 " // define parameter triangulation\n"
1193 " Standard_Real aDeflection = 0.1;\n"
1195 " // removes all the triangulations of the faces ,\n"
1196 " //and all the polygons on the triangulations of the edges\n"
1197 " BRepTools::Clean(aShape);\n"
1198 " // adds a triangulation of the shape aShape with the deflection aDeflection\n"
1199 " BRepMesh::Mesh(aShape,aDeflection);\n"
1201 " Standard_Integer aIndex = 1, nbNodes = 0;\n"
1203 " // define two sequence of points\n"
1204 " TColgp_SequenceOfPnt aPoints, aPoints1;\n"
1206 " // triangulation\n"
1207 " for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())\n"
1209 " TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());\n"
1210 " TopLoc_Location aLocation;\n"
1212 " // takes the triangulation of the face aFace\n"
1213 " Handle(Poly_Triangulation) aTr = BRep_Tool::Triangulation(aFace,aLocation);\n"
1215 " if(!aTr.IsNull())\n"
1217 " // takes the array of nodes for this triangulation\n"
1218 " const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); \n"
1219 " nbNodes = aNodes.Length();\n"
1221 " for( Standard_Integer i = 1; i <= nbNodes; i++)\n"
1223 " // create seguence of node points in absolute coordinate system\n"
1224 " gp_Pnt aPnt = aNodes(i).Transformed(aLocation);\n"
1225 " aPoints.Append(aPnt);\n"
1231 " // remove double points\n"
1232 " nbNodes = aPoints.Length();\n"
1233 " for( Standard_Integer i = 1; i <= nbNodes; i++)\n"
1235 " gp_Pnt aPi = aPoints(i);\n"
1236 " for( Standard_Integer j = i + 1; j < nbNodes; j++)\n"
1238 " gp_Pnt aPj = aPoints(j);\n"
1239 " if(!aPi.IsEqual(aPj,0.9))\n"
1242 " if(aIndex == j - 1)\n"
1243 " aPoints1.Append(aPi);\n"
1245 " aIndex = i + 1;\n"
1248 " // find max point\n"
1250 " gp_Pnt aPntMax = aPoints1(1);\n"
1251 " nbNodes = aPoints1.Length();\n"
1252 " for(i = 2; i <= nbNodes; i++)\n"
1254 " if(aPoints1(i).X() > aPntMax.X())\n"
1257 " aPntMax = aPoints1(aIndex); \n"
1261 " // clear seguence\n"
1262 " aPoints.Clear();\n"
1264 " Standard_Integer nbLeftNodes = nbNodes;\n"
1266 " // ascending sort - fill aPoints with ascending \n"
1267 " // by X coordinate points from aPoints1\n"
1268 " for(i = 1; i < nbNodes; i++)\n"
1270 " Standard_Real aMin = aPntMax.X();\n"
1272 " for( Standard_Integer j = 1; j <= nbLeftNodes; j++)\n"
1274 " if(aPoints1(j).X() < aMin)\n"
1276 " aMin = aPoints1(j).X();\n"
1280 " aPoints.Append(aPoints1(aIndex));\n"
1281 " aPoints1.Remove(aIndex);\n"
1282 " nbLeftNodes = aPoints1.Length();\n"
1284 " aPoints.Append(aPntMax);\n"
1286 " // define parameters GeomPlate_BuildPlateSurface\n"
1287 " Standard_Integer Degree = 3;\n"
1288 " Standard_Integer NbPtsOnCur = 10;\n"
1289 " Standard_Integer NbIter = 3;\n"
1290 " Standard_Integer Order = 0;\n"
1291 " Standard_Integer MaxSeg = 9;\n"
1292 " Standard_Integer MaxDegree = 5;\n"
1293 " Standard_Real dmax, anApproxTol = 0.001;\n"
1294 " Standard_Real aConstrTol = Precision::Confusion();\n"
1296 " // define object BuildPlateSurface\n"
1297 " GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);\n"
1299 " // add point constraints to GeomPlate_BuildPlateSurface object\n"
1300 " nbNodes = aPoints.Length();\n"
1301 " for (i = 1; i <= nbNodes; i++)\n"
1302 " BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));\n"
1304 " BPSurf.Perform();\n"
1306 " // make PlateSurface\n"
1307 " Handle(GeomPlate_Surface) PSurf;\n"
1308 " Handle(Geom_Surface) aSurf;\n"
1310 " if (BPSurf.IsDone())\n"
1312 " PSurf = BPSurf.Surface();\n"
1314 " // define parameter approximation\n"
1315 " dmax = Max(0.01,10*BPSurf.G0Error());\n"
1317 " // make approximation\n"
1318 " GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);\n"
1319 " aSurf = Mapp.Surface();\n"
1324 " ShapeAnalysis_FreeBounds aFreeBounds(aShape, Standard_False, Standard_True);\n"
1325 " TopoDS_Compound aClosedWires = aFreeBounds.GetClosedWires();\n"
1326 " TopTools_IndexedMapOfShape aWires;\n"
1327 " TopExp::MapShapes(aClosedWires, TopAbs_WIRE, aWires);\n"
1328 " TopoDS_Wire aWire;\n"
1329 " Standard_Integer nbWires = aWires.Extent();\n"
1331 " aWire = TopoDS::Wire(aWires(1));\n"
1335 " BRep_Builder B;\n"
1336 " TopoDS_Face aFace;\n"
1337 " B.MakeFace(aFace, aSurf, Precision::Confusion());\n"
1338 " B.Add(aFace, aWire);\n"
1339 " Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape(aFace);\n"
1340 " sfs->Perform();\n"
1341 " TopoDS_Shape aFixedFace = sfs->Shape();\n"
1342 " if (aFixedFace.IsNull()) \n"
1345 // define parameter triangulation
1346 Standard_Real aDeflection = 0.1;
1348 // removes all the triangulations of the faces ,
1349 //and all the polygons on the triangulations of the edges
1350 BRepTools::Clean(aShape);
1351 // adds a triangulation of the shape aShape with the deflection aDeflection
1352 BRepMesh_IncrementalMesh(aShape,aDeflection);
1354 Standard_Integer aIndex = 1, nbNodes = 0;
1356 // define two sequence of points
1357 TColgp_SequenceOfPnt aPoints, aPoints1;
1360 for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())
1362 TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());
1363 TopLoc_Location aLocation;
1365 // takes the triangulation of the face aFace
1366 Handle(Poly_Triangulation) aTr = BRep_Tool::Triangulation(aFace,aLocation);
1370 // takes the array of nodes for this triangulation
1371 const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
1372 nbNodes = aNodes.Length();
1374 for( Standard_Integer i = 1; i <= nbNodes; i++)
1376 // create seguence of node points in absolute coordinate system
1377 gp_Pnt aPnt = aNodes(i).Transformed(aLocation);
1378 aPoints.Append(aPnt);
1384 // remove double points
1385 nbNodes = aPoints.Length();
1387 for( i = 1; i <= nbNodes; i++)
1389 gp_Pnt aPi = aPoints(i);
1391 for( j = i + 1; j < nbNodes; j++)
1393 gp_Pnt aPj = aPoints(j);
1394 if(!aPi.IsEqual(aPj,0.9))
1398 aPoints1.Append(aPi);
1405 gp_Pnt aPntMax = aPoints1(1);
1406 nbNodes = aPoints1.Length();
1407 for(i = 2; i <= nbNodes; i++)
1409 if(aPoints1(i).X() > aPntMax.X())
1412 aPntMax = aPoints1(aIndex);
1419 Standard_Integer nbLeftNodes = nbNodes;
1421 // ascending sort - fill aPoints with ascending
1422 // by X coordinate points from aPoints1
1423 for(i = 1; i < nbNodes; i++)
1425 Standard_Real aMin = aPntMax.X();
1427 for( Standard_Integer j = 1; j <= nbLeftNodes; j++)
1429 if(aPoints1(j).X() < aMin)
1431 aMin = aPoints1(j).X();
1435 aPoints.Append(aPoints1(aIndex));
1436 aPoints1.Remove(aIndex);
1437 nbLeftNodes = aPoints1.Length();
1439 aPoints.Append(aPntMax);
1441 // define parameters GeomPlate_BuildPlateSurface
1442 Standard_Integer Degree = 3;
1443 Standard_Integer NbPtsOnCur = 10;
1444 Standard_Integer NbIter = 3;
1445 Standard_Integer Order = 0;
1446 Standard_Integer MaxSeg = 9;
1447 Standard_Integer MaxDegree = 5;
1448 Standard_Real dmax, anApproxTol = 0.001;
1449 Standard_Real aConstrTol = Precision::Confusion();
1451 // define object BuildPlateSurface
1452 GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);
1454 // add point constraints to GeomPlate_BuildPlateSurface object
1455 nbNodes = aPoints.Length();
1456 for (i = 1; i <= nbNodes; i++)
1457 BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));
1461 // make PlateSurface
1462 Handle(GeomPlate_Surface) PSurf;
1463 Handle(Geom_Surface) aSurf;
1465 if (BPSurf.IsDone())
1467 PSurf = BPSurf.Surface();
1469 // define parameter approximation
1470 dmax = Max(0.01,10*BPSurf.G0Error());
1472 // make approximation
1473 GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);
1474 aSurf = Mapp.Surface();
1479 ShapeAnalysis_FreeBounds aFreeBounds(aShape, Standard_False, Standard_True);
1480 TopoDS_Compound aClosedWires = aFreeBounds.GetClosedWires();
1481 TopTools_IndexedMapOfShape aWires;
1482 TopExp::MapShapes(aClosedWires, TopAbs_WIRE, aWires);
1484 Standard_Integer nbWires = aWires.Extent();
1486 aWire = TopoDS::Wire(aWires(1));
1492 B.MakeFace(aFace, aSurf, Precision::Confusion());
1493 B.Add(aFace, aWire);
1494 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape(aFace);
1496 TopoDS_Shape aFixedFace = sfs->Shape();
1497 if (aFixedFace.IsNull())
1500 // output surface, make it half transparent
1501 Handle(AIS_InteractiveObject) aSurfIO = drawSurface(
1502 aSurf, Quantity_NOC_LEMONCHIFFON3, Standard_False);
1503 aSurfIO->SetTransparency(0.5);
1504 myAISContext->Display(aSurfIO,Standard_False);
1507 if(WAIT_A_LITTLE) return;
1510 for(i = 1; i <= nbNodes; i++)
1511 drawPoint(aPoints(i));
1513 if(WAIT_A_LITTLE) return;
1515 // output resulting face
1516 drawShape(aFixedFace);
1519 Handle(AIS_InteractiveObject) CGeometryDoc::drawSurface
1520 (const Handle(Geom_Surface)& theSurface,
1521 const Quantity_Color& theColor,
1522 const Standard_Boolean toDisplay)
1524 Standard_Real u1, u2, v1, v2;
1525 theSurface->Bounds(u1,u2,v1,v2);
1531 Handle(AIS_Shape) aGraphicSurface =
1532 new AIS_Shape(BRepBuilderAPI_MakeFace (theSurface, u1, u2, v1, v2, Precision::Confusion()));
1534 myAISContext->SetMaterial(aGraphicSurface, Graphic3d_NOM_PLASTIC, toDisplay);
1535 myAISContext->SetColor(aGraphicSurface, theColor, toDisplay);
1540 myAISContext->Display (aGraphicSurface, Standard_False);
1544 myAISContext->Display (aGraphicSurface, Standard_True);
1547 return aGraphicSurface;
1550 Standard_Boolean CGeometryDoc::WaitForInput (unsigned long aMilliSeconds)
1552 //::WaitForSingleObject(::CreateEvent (NULL, FALSE, FALSE, NULL), aMilliSeconds);
1553 if (::MsgWaitForMultipleObjects(0, NULL, FALSE, aMilliSeconds,
1554 QS_KEY | QS_MOUSEBUTTON) != WAIT_TIMEOUT)
1557 if (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
1559 if (msg.message == WM_KEYUP)
1561 ::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE);
1562 return WaitForInput (aMilliSeconds);
1565 return Standard_True;
1568 return Standard_False;
1571 Handle(AIS_Point) CGeometryDoc::drawPoint
1572 (const gp_Pnt& aPnt,
1573 const Quantity_Color& theColor,
1574 const Standard_Boolean toDisplay)
1576 Handle(AIS_Point) aGraphicPoint = new AIS_Point (new Geom_CartesianPoint(aPnt));
1578 myAISContext->SetColor (aGraphicPoint, theColor, toDisplay);
1581 myAISContext->Display (aGraphicPoint, Standard_True);
1582 //COCCDemoDoc::Fit();
1585 return aGraphicPoint;
1588 Handle(AIS_Shape) CGeometryDoc::drawShape
1589 (const TopoDS_Shape& theShape,
1590 const Graphic3d_NameOfMaterial theMaterial,
1591 const Standard_Boolean toDisplay)
1593 Handle(AIS_Shape) aGraphicShape = new AIS_Shape(theShape);
1595 myAISContext->SetMaterial(aGraphicShape, theMaterial, toDisplay);
1600 myAISContext->Display (aGraphicShape, Standard_False);
1604 myAISContext->Display (aGraphicShape, Standard_True);
1607 return aGraphicShape;