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 Standard_Real 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(Standard_Real 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 Standard_Real& 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 anOCCTDataPathValue;
1074 anOCCTDataPathValue.GetEnvironmentVariable(L"CSF_OCCTDataPath");
1075 CString initdir = (anOCCTDataPathValue + L"\\occ\\SurfaceFromPoints");
1077 dlg.m_ofn.lpstrInitialDir = initdir;
1079 if (dlg.DoModal() == IDOK)
1081 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
1082 CString filename = dlg.GetPathName();
1085 std::istream in(&fic);
1086 if (!fic.open (filename, std::ios::in))
1087 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Unable to open file", L"CasCade Error", MB_ICONERROR);
1089 TColgp_SequenceOfXYZ seqOfXYZ;
1091 Standard_Integer nbPnt=0;
1092 Standard_Real x,y,z;
1096 while (!in.fail()|| !in.eof())
1098 if (in >> x && in >> y && in >> z){
1103 seqOfXYZ.Append(pntXYZ);
1104 BRepBuilderAPI_MakeVertex V(gp_Pnt(x, y, z));
1105 B.Add(C,V.Vertex());
1109 Handle(AIS_Shape) anAISCompound = new AIS_Shape(C);
1110 myAISContext->Display(anAISCompound, Standard_False);
1114 sol.Build(seqOfXYZ);
1116 if (sol.IsDone() == Standard_True)
1118 Handle(Geom_BSplineSurface) GeomSol = sol.Surface();
1119 TopoDS_Face aface = BRepBuilderAPI_MakeFace(GeomSol, Precision::Confusion());
1120 if (!BRepAlgo::IsValid(aface))
1121 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : The plate surface is not valid!", L"CasCade Error", MB_ICONERROR);
1122 Handle(AIS_Shape) anAISShape=new AIS_Shape(aface);
1123 myAISContext->Display(anAISShape, Standard_False);
1127 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Computation has failed", L"CasCade Error", MB_ICONERROR);
1131 /*********************************************************************************************
1132 ********************** S I M P L I F Y *****************************************************
1133 *********************************************************************************************/
1135 //================================================================
1136 // Function : fixParam
1137 // Purpose : assings a finite value to theParam if it intinite
1138 // (equal to +- Precision::Infinite())
1139 //================================================================
1140 static Standard_Boolean fixParam(Standard_Real& theParam)
1142 Standard_Boolean aResult = Standard_False;
1143 if (Precision::IsNegativeInfinite(theParam))
1145 theParam = -MAX_PARAM;
1146 aResult = Standard_True;
1148 if (Precision::IsPositiveInfinite(theParam))
1150 theParam = MAX_PARAM;
1151 aResult = Standard_True;
1157 void CGeometryDoc::OnSimplify()
1159 CString anOCCTDataPathValue;
1160 anOCCTDataPathValue.GetEnvironmentVariable(L"CSF_OCCTDataPath");
1161 CString initfile = (anOCCTDataPathValue + L"\\occ\\shell1.brep");
1163 std::filebuf aFileBuf;
1164 std::istream aStream (&aFileBuf);
1165 if (!aFileBuf.open (initfile, std::ios::in))
1167 initfile += L" was not found. The sample can not be shown.";
1168 myCResultDialog.SetText (initfile);
1172 TopoDS_Shape aShape;
1174 BRepTools::Read (aShape, aStream, aBld);
1175 if (aShape.IsNull())
1177 initfile += L" is invalid file. The sample can not be shown.";
1178 myCResultDialog.SetText(initfile);
1181 myAISContext->SetDisplayMode(AIS_Shaded, Standard_True);
1185 void CGeometryDoc::simplify(const TopoDS_Shape& aShape)
1187 myCResultDialog.SetTitle("Simplify Face");
1188 myCResultDialog.SetText(" TopoDS_Shape aShape;\n"
1190 " // initialize aShape\n"
1193 " // define parameter triangulation\n"
1194 " Standard_Real aDeflection = 0.1;\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"
1202 " Standard_Integer aIndex = 1, nbNodes = 0;\n"
1204 " // define two sequence of points\n"
1205 " TColgp_SequenceOfPnt aPoints, aPoints1;\n"
1207 " // triangulation\n"
1208 " for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())\n"
1210 " TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());\n"
1211 " TopLoc_Location aLocation;\n"
1213 " // takes the triangulation of the face aFace\n"
1214 " Handle(Poly_Triangulation) aTr = BRep_Tool::Triangulation(aFace,aLocation);\n"
1216 " if(!aTr.IsNull())\n"
1218 " // takes the array of nodes for this triangulation\n"
1219 " const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); \n"
1220 " nbNodes = aNodes.Length();\n"
1222 " for( Standard_Integer i = 1; i <= nbNodes; i++)\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"
1232 " // remove double points\n"
1233 " nbNodes = aPoints.Length();\n"
1234 " for( Standard_Integer i = 1; i <= nbNodes; i++)\n"
1236 " gp_Pnt aPi = aPoints(i);\n"
1237 " for( Standard_Integer j = i + 1; j < nbNodes; j++)\n"
1239 " gp_Pnt aPj = aPoints(j);\n"
1240 " if(!aPi.IsEqual(aPj,0.9))\n"
1243 " if(aIndex == j - 1)\n"
1244 " aPoints1.Append(aPi);\n"
1246 " aIndex = i + 1;\n"
1249 " // find max point\n"
1251 " gp_Pnt aPntMax = aPoints1(1);\n"
1252 " nbNodes = aPoints1.Length();\n"
1253 " for(i = 2; i <= nbNodes; i++)\n"
1255 " if(aPoints1(i).X() > aPntMax.X())\n"
1258 " aPntMax = aPoints1(aIndex); \n"
1262 " // clear seguence\n"
1263 " aPoints.Clear();\n"
1265 " Standard_Integer nbLeftNodes = nbNodes;\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"
1271 " Standard_Real aMin = aPntMax.X();\n"
1273 " for( Standard_Integer j = 1; j <= nbLeftNodes; j++)\n"
1275 " if(aPoints1(j).X() < aMin)\n"
1277 " aMin = aPoints1(j).X();\n"
1281 " aPoints.Append(aPoints1(aIndex));\n"
1282 " aPoints1.Remove(aIndex);\n"
1283 " nbLeftNodes = aPoints1.Length();\n"
1285 " aPoints.Append(aPntMax);\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"
1297 " // define object BuildPlateSurface\n"
1298 " GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);\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"
1305 " BPSurf.Perform();\n"
1307 " // make PlateSurface\n"
1308 " Handle(GeomPlate_Surface) PSurf;\n"
1309 " Handle(Geom_Surface) aSurf;\n"
1311 " if (BPSurf.IsDone())\n"
1313 " PSurf = BPSurf.Surface();\n"
1315 " // define parameter approximation\n"
1316 " dmax = Max(0.01,10*BPSurf.G0Error());\n"
1318 " // make approximation\n"
1319 " GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);\n"
1320 " aSurf = Mapp.Surface();\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"
1332 " aWire = TopoDS::Wire(aWires(1));\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"
1340 " Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape(aFace);\n"
1341 " sfs->Perform();\n"
1342 " TopoDS_Shape aFixedFace = sfs->Shape();\n"
1343 " if (aFixedFace.IsNull()) \n"
1346 // define parameter triangulation
1347 Standard_Real aDeflection = 0.1;
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
1353 BRepMesh_IncrementalMesh(aShape,aDeflection);
1355 Standard_Integer aIndex = 1, nbNodes = 0;
1357 // define two sequence of points
1358 TColgp_SequenceOfPnt aPoints, aPoints1;
1361 for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())
1363 TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());
1364 TopLoc_Location aLocation;
1366 // takes the triangulation of the face aFace
1367 Handle(Poly_Triangulation) aTr = BRep_Tool::Triangulation(aFace,aLocation);
1371 // takes the array of nodes for this triangulation
1372 const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
1373 nbNodes = aNodes.Length();
1375 for( Standard_Integer i = 1; i <= nbNodes; i++)
1377 // create seguence of node points in absolute coordinate system
1378 gp_Pnt aPnt = aNodes(i).Transformed(aLocation);
1379 aPoints.Append(aPnt);
1385 // remove double points
1386 nbNodes = aPoints.Length();
1388 for( i = 1; i <= nbNodes; i++)
1390 gp_Pnt aPi = aPoints(i);
1392 for( j = i + 1; j < nbNodes; j++)
1394 gp_Pnt aPj = aPoints(j);
1395 if(!aPi.IsEqual(aPj,0.9))
1399 aPoints1.Append(aPi);
1406 gp_Pnt aPntMax = aPoints1(1);
1407 nbNodes = aPoints1.Length();
1408 for(i = 2; i <= nbNodes; i++)
1410 if(aPoints1(i).X() > aPntMax.X())
1413 aPntMax = aPoints1(aIndex);
1420 Standard_Integer nbLeftNodes = nbNodes;
1422 // ascending sort - fill aPoints with ascending
1423 // by X coordinate points from aPoints1
1424 for(i = 1; i < nbNodes; i++)
1426 Standard_Real aMin = aPntMax.X();
1428 for( Standard_Integer j = 1; j <= nbLeftNodes; j++)
1430 if(aPoints1(j).X() < aMin)
1432 aMin = aPoints1(j).X();
1436 aPoints.Append(aPoints1(aIndex));
1437 aPoints1.Remove(aIndex);
1438 nbLeftNodes = aPoints1.Length();
1440 aPoints.Append(aPntMax);
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();
1452 // define object BuildPlateSurface
1453 GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);
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));
1462 // make PlateSurface
1463 Handle(GeomPlate_Surface) PSurf;
1464 Handle(Geom_Surface) aSurf;
1466 if (BPSurf.IsDone())
1468 PSurf = BPSurf.Surface();
1470 // define parameter approximation
1471 dmax = Max(0.01,10*BPSurf.G0Error());
1473 // make approximation
1474 GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);
1475 aSurf = Mapp.Surface();
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);
1485 Standard_Integer nbWires = aWires.Extent();
1487 aWire = TopoDS::Wire(aWires(1));
1493 B.MakeFace(aFace, aSurf, Precision::Confusion());
1494 B.Add(aFace, aWire);
1495 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape(aFace);
1497 TopoDS_Shape aFixedFace = sfs->Shape();
1498 if (aFixedFace.IsNull())
1501 // output surface, make it half transparent
1502 Handle(AIS_InteractiveObject) aSurfIO = drawSurface(
1503 aSurf, Quantity_NOC_LEMONCHIFFON3, Standard_False);
1504 aSurfIO->SetTransparency(0.5);
1505 myAISContext->Display(aSurfIO,Standard_False);
1508 if(WAIT_A_LITTLE) return;
1511 for(i = 1; i <= nbNodes; i++)
1512 drawPoint(aPoints(i));
1514 if(WAIT_A_LITTLE) return;
1516 // output resulting face
1517 drawShape(aFixedFace);
1520 Handle(AIS_InteractiveObject) CGeometryDoc::drawSurface
1521 (const Handle(Geom_Surface)& theSurface,
1522 const Quantity_Color& theColor,
1523 const Standard_Boolean toDisplay)
1525 Standard_Real u1, u2, v1, v2;
1526 theSurface->Bounds(u1,u2,v1,v2);
1532 Handle(AIS_Shape) aGraphicSurface =
1533 new AIS_Shape(BRepBuilderAPI_MakeFace (theSurface, u1, u2, v1, v2, Precision::Confusion()));
1535 myAISContext->SetMaterial(aGraphicSurface, Graphic3d_NOM_PLASTIC, toDisplay);
1536 myAISContext->SetColor(aGraphicSurface, theColor, toDisplay);
1541 myAISContext->Display (aGraphicSurface, Standard_False);
1545 myAISContext->Display (aGraphicSurface, Standard_True);
1548 return aGraphicSurface;
1551 Standard_Boolean CGeometryDoc::WaitForInput (unsigned long aMilliSeconds)
1553 //::WaitForSingleObject(::CreateEvent (NULL, FALSE, FALSE, NULL), aMilliSeconds);
1554 if (::MsgWaitForMultipleObjects(0, NULL, FALSE, aMilliSeconds,
1555 QS_KEY | QS_MOUSEBUTTON) != WAIT_TIMEOUT)
1558 if (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
1560 if (msg.message == WM_KEYUP)
1562 ::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE);
1563 return WaitForInput (aMilliSeconds);
1566 return Standard_True;
1569 return Standard_False;
1572 Handle(AIS_Point) CGeometryDoc::drawPoint
1573 (const gp_Pnt& aPnt,
1574 const Quantity_Color& theColor,
1575 const Standard_Boolean toDisplay)
1577 Handle(AIS_Point) aGraphicPoint = new AIS_Point (new Geom_CartesianPoint(aPnt));
1579 myAISContext->SetColor (aGraphicPoint, theColor, toDisplay);
1582 myAISContext->Display (aGraphicPoint, Standard_True);
1583 //COCCDemoDoc::Fit();
1586 return aGraphicPoint;
1589 Handle(AIS_Shape) CGeometryDoc::drawShape
1590 (const TopoDS_Shape& theShape,
1591 const Graphic3d_NameOfMaterial theMaterial,
1592 const Standard_Boolean toDisplay)
1594 Handle(AIS_Shape) aGraphicShape = new AIS_Shape(theShape);
1596 myAISContext->SetMaterial(aGraphicShape, theMaterial, toDisplay);
1601 myAISContext->Display (aGraphicShape, Standard_False);
1605 myAISContext->Display (aGraphicShape, Standard_True);
1608 return aGraphicShape;