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 assigned
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->SelectDetected();
248 myAISContext2D->UpdateCurrentViewer();
251 //-----------------------------------------------------------------------------------------
253 //-----------------------------------------------------------------------------------------
254 void CGeometryDoc::MoveEvent2D(const Standard_Integer x,
255 const Standard_Integer y,
256 const Handle(V3d_View)& aView)
258 if (aView->Viewer()->IsGridActive())
260 Standard_Real aGridX=0,aGridY=0,aGridZ=0;
261 aView->ConvertToGrid(x,y,aGridX,aGridY,aGridZ);
262 //View is not updated automatically in ConvertToGrid
265 this->myAISContext2D->MoveTo (x, y, aView, Standard_True);
268 //-----------------------------------------------------------------------------------------
270 //-----------------------------------------------------------------------------------------
271 void CGeometryDoc::ShiftMoveEvent2D(const Standard_Integer /*x*/,
272 const Standard_Integer /*y*/,
273 const Handle(V3d_View)& /*aView*/)
277 //-----------------------------------------------------------------------------------------
279 //-----------------------------------------------------------------------------------------
280 void CGeometryDoc::ShiftDragEvent2D(const Standard_Integer /*x*/,
281 const Standard_Integer /*y*/,
282 const Standard_Integer /*TheState*/,
283 const Handle(V3d_View)& /*aView*/)
288 //-----------------------------------------------------------------------------------------
290 //-----------------------------------------------------------------------------------------
291 void CGeometryDoc::ShiftInputEvent2D(const Standard_Integer /*x*/,
292 const Standard_Integer /*y*/,
293 const Handle(V3d_View)& /*aView*/)
297 //-----------------------------------------------------------------------------------------
299 //-----------------------------------------------------------------------------------------
300 void CGeometryDoc::Popup2D(const Standard_Integer x,
301 const Standard_Integer y,
302 const Handle(V3d_View)& aView)
305 VERIFY(menu.LoadMenu(IDR_Popup3D));
308 pPopup = menu.GetSubMenu(0);
310 ASSERT(pPopup != NULL);
312 POINT winCoord = { x , y };
313 Handle(WNT_Window) aWNTWindow=
314 Handle(WNT_Window)::DownCast(aView->Window());
315 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
316 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
321 //-----------------------------------------------------------------------------------------
323 //-----------------------------------------------------------------------------------------
324 void CGeometryDoc::Popup (const Standard_Integer theMouseX,
325 const Standard_Integer theMouseY,
326 const Handle(V3d_View)& theView)
328 Standard_Integer PopupMenuNumber=0;
329 GetAISContext()->InitSelected();
330 if (GetAISContext()->MoreSelected())
336 VERIFY(menu.LoadMenu(IDR_Popup3D));
337 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
338 ASSERT(pPopup != NULL);
340 POINT winCoord = { theMouseX , theMouseY };
341 Handle(WNT_Window) aWNTWindow = Handle(WNT_Window)::DownCast(theView->Window());
342 ClientToScreen ( (HWND)(aWNTWindow->HWindow()), &winCoord );
344 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON ,
345 winCoord.x, winCoord.y ,
349 //-----------------------------------------------------------------------------------------
351 //-----------------------------------------------------------------------------------------
352 void CGeometryDoc::InputEvent (const Standard_Integer /*theMouseX*/,
353 const Standard_Integer /*theMouseY*/,
354 const Handle(V3d_View)& /*theView*/)
356 myAISContext->SelectDetected();
357 myAISContext2D->UpdateCurrentViewer();
360 //-----------------------------------------------------------------------------------------
362 //-----------------------------------------------------------------------------------------
363 void CGeometryDoc::Put2DOnTop(bool isMax)
365 POSITION position = GetFirstViewPosition();
366 while (position != (POSITION)NULL)
368 CView* pCurrentView = (CView*)GetNextView(position);
369 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
371 ASSERT_VALID(pCurrentView);
372 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
373 ASSERT(pParentFrm != (CFrameWnd *)NULL);
374 // simply make the frame window visible
377 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
381 pParentFrm->ActivateFrame(SW_SHOW);
387 //-----------------------------------------------------------------------------------------
389 //-----------------------------------------------------------------------------------------
390 void CGeometryDoc::Minimize2D()
392 POSITION position = GetFirstViewPosition();
393 while (position != (POSITION)NULL)
395 CView* pCurrentView = (CView*)GetNextView(position);
396 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
398 ASSERT_VALID(pCurrentView);
399 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
400 ASSERT(pParentFrm != (CFrameWnd *)NULL);
401 // simply make the frame window visible
402 pParentFrm->ActivateFrame(SW_HIDE);
407 //-----------------------------------------------------------------------------------------
409 //-----------------------------------------------------------------------------------------
410 void CGeometryDoc::Fit2DViews()
412 POSITION position = GetFirstViewPosition();
413 while (position != (POSITION)NULL)
415 CView* pCurrentView = (CView*)GetNextView(position);
416 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
418 ASSERT_VALID(pCurrentView);
419 CGeometryView2D* aCGeometryView2D = (CGeometryView2D*)pCurrentView;
420 aCGeometryView2D->FitAll();
425 //-----------------------------------------------------------------------------------------
427 //-----------------------------------------------------------------------------------------
428 void CGeometryDoc::Put3DOnTop(bool isMax)
430 POSITION position = GetFirstViewPosition();
431 while (position != (POSITION)NULL)
433 CView* pCurrentView = (CView*)GetNextView(position);
434 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
436 ASSERT_VALID(pCurrentView);
437 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
438 ASSERT(pParentFrm != (CFrameWnd *)NULL);
439 // simply make the frame window visible
442 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
446 pParentFrm->ActivateFrame(SW_SHOW);
452 //-----------------------------------------------------------------------------------------
454 //-----------------------------------------------------------------------------------------
455 void CGeometryDoc::Minimize3D()
457 POSITION position = GetFirstViewPosition();
458 while (position != (POSITION)NULL)
460 CView* pCurrentView = (CView*)GetNextView(position);
461 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
463 ASSERT_VALID(pCurrentView);
464 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
465 ASSERT(pParentFrm != (CFrameWnd *)NULL);
466 // simply make the frame window visible
467 pParentFrm->ActivateFrame(SW_HIDE);
472 //-----------------------------------------------------------------------------------------
474 //-----------------------------------------------------------------------------------------
475 void CGeometryDoc::Fit3DViews(Standard_Real Coef)
477 POSITION position = GetFirstViewPosition();
478 while (position != (POSITION)NULL)
480 CView* pCurrentView = (CView*)GetNextView(position);
481 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
483 ASSERT_VALID(pCurrentView);
484 CGeometryView* aCGeometryView = (CGeometryView*)pCurrentView;
485 aCGeometryView->FitAll(Coef);
490 //-----------------------------------------------------------------------------------------
492 //-----------------------------------------------------------------------------------------
493 void CGeometryDoc::Set3DViewsZoom(const Standard_Real& Coef)
495 POSITION position = GetFirstViewPosition();
496 while (position != (POSITION)NULL)
498 CView* pCurrentView = (CView*)GetNextView(position);
499 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
501 ASSERT_VALID(pCurrentView);
502 CGeometryView* aCGeometryView = (CGeometryView*)pCurrentView;
503 aCGeometryView->SetZoom( Coef );
508 //-----------------------------------------------------------------------------------------
509 // Buttons event handlers
510 //-----------------------------------------------------------------------------------------
511 void CGeometryDoc::OnBUTTONTest1()
513 GeomSources::gpTest1(this); }
514 void CGeometryDoc::OnBUTTONTest2()
516 GeomSources::gpTest2(this); }
517 void CGeometryDoc::OnBUTTONTest3()
519 GeomSources::gpTest3(this); }
520 void CGeometryDoc::OnBUTTONTest4()
522 GeomSources::gpTest4(this); }
523 void CGeometryDoc::OnBUTTONTest5()
525 GeomSources::gpTest5(this); }
526 void CGeometryDoc::OnBUTTONTest6()
528 GeomSources::gpTest6(this); }
529 void CGeometryDoc::OnBUTTONTest7()
531 GeomSources::gpTest7(this); }
532 void CGeometryDoc::OnBUTTONTest8()
534 GeomSources::gpTest8(this); }
535 void CGeometryDoc::OnBUTTONTest9()
537 GeomSources::gpTest9(this); }
538 void CGeometryDoc::OnBUTTONTest10()
540 GeomSources::gpTest10(this); }
541 void CGeometryDoc::OnBUTTONTest11()
543 GeomSources::gpTest11(this); }
544 void CGeometryDoc::OnBUTTONTest12()
546 GeomSources::gpTest12(this); }
547 void CGeometryDoc::OnBUTTONTest13()
549 GeomSources::gpTest13(this); }
550 void CGeometryDoc::OnBUTTONTest14()
552 GeomSources::gpTest14(this); }
553 void CGeometryDoc::OnBUTTONTest15()
555 GeomSources::gpTest15(this); }
556 void CGeometryDoc::OnBUTTONTest16()
558 GeomSources::gpTest16(this); }
559 void CGeometryDoc::OnBUTTONTest17()
561 GeomSources::gpTest17(this); }
562 void CGeometryDoc::OnBUTTONTest18()
564 GeomSources::gpTest18(this); }
565 void CGeometryDoc::OnBUTTONTest19()
567 GeomSources::gpTest19(this); }
568 void CGeometryDoc::OnBUTTONTest20()
570 GeomSources::gpTest20(this); }
571 void CGeometryDoc::OnBUTTONTest21()
573 GeomSources::gpTest21(this); }
574 void CGeometryDoc::OnBUTTONTest22()
576 GeomSources::gpTest22(this); }
577 void CGeometryDoc::OnBUTTONTest23()
579 GeomSources::gpTest23(this); }
580 void CGeometryDoc::OnBUTTONTest24()
582 GeomSources::gpTest24(this); }
583 void CGeometryDoc::OnBUTTONTest25()
585 GeomSources::gpTest25(this); }
586 void CGeometryDoc::OnBUTTONTest26()
588 GeomSources::gpTest26(this); }
589 void CGeometryDoc::OnBUTTONTest27()
591 GeomSources::gpTest27(this); }
592 void CGeometryDoc::OnBUTTONTest28()
594 GeomSources::gpTest28(this); }
595 void CGeometryDoc::OnBUTTONTest29()
597 GeomSources::gpTest29(this); }
598 void CGeometryDoc::OnBUTTONTest30()
600 GeomSources::gpTest30(this); }
601 void CGeometryDoc::OnBUTTONTest31()
603 GeomSources::gpTest31(this); }
604 void CGeometryDoc::OnBUTTONTest32()
606 GeomSources::gpTest32(this); }
607 void CGeometryDoc::OnBUTTONTest33()
609 GeomSources::gpTest33(this); }
610 void CGeometryDoc::OnBUTTONTest34()
612 GeomSources::gpTest34(this); }
613 void CGeometryDoc::OnBUTTONTest35()
615 GeomSources::gpTest35(this); }
616 void CGeometryDoc::OnBUTTONTest36()
618 GeomSources::gpTest36(this); }
620 void CGeometryDoc::OnBUTTONTest37()
622 GeomSources::gpTest37(this); }
623 void CGeometryDoc::OnBUTTONTest38()
625 GeomSources::gpTest38(this); }
626 void CGeometryDoc::OnBUTTONTest39()
628 GeomSources::gpTest39(this); }
629 void CGeometryDoc::OnBUTTONTest40()
631 GeomSources::gpTest40(this); }
632 void CGeometryDoc::OnBUTTONTest41()
634 GeomSources::gpTest41(this); }
635 void CGeometryDoc::OnBUTTONTest42()
637 GeomSources::gpTest42(this); }
638 void CGeometryDoc::OnBUTTONTest43()
640 GeomSources::gpTest43(this); }
641 void CGeometryDoc::OnBUTTONTest44()
643 GeomSources::gpTest44(this); }
644 void CGeometryDoc::OnBUTTONTest45()
646 GeomSources::gpTest45(this); }
647 void CGeometryDoc::OnBUTTONTest46()
649 GeomSources::gpTest46(this); }
650 void CGeometryDoc::OnBUTTONTest47()
652 GeomSources::gpTest47(this); }
653 void CGeometryDoc::OnBUTTONTest48()
655 GeomSources::gpTest48(this); }
656 void CGeometryDoc::OnBUTTONTest49()
658 GeomSources::gpTest49(this); }
659 void CGeometryDoc::OnBUTTONTest50()
661 GeomSources::gpTest50(this); }
663 void CGeometryDoc::OnUpdateBUTTONTest1(CCmdUI* pCmdUI)
666 pCmdUI->SetCheck(true);
668 pCmdUI->SetCheck(false);
671 void CGeometryDoc::OnUpdateBUTTONTest2(CCmdUI* pCmdUI)
674 pCmdUI->SetCheck(true);
676 pCmdUI->SetCheck(false);
679 void CGeometryDoc::OnUpdateBUTTONTest3(CCmdUI* pCmdUI)
682 pCmdUI->SetCheck(true);
684 pCmdUI->SetCheck(false);
687 void CGeometryDoc::OnUpdateBUTTONTest4(CCmdUI* pCmdUI)
690 pCmdUI->SetCheck(true);
692 pCmdUI->SetCheck(false);
695 void CGeometryDoc::OnUpdateBUTTONTest5(CCmdUI* pCmdUI)
698 pCmdUI->SetCheck(true);
700 pCmdUI->SetCheck(false);
703 void CGeometryDoc::OnUpdateBUTTONTest6(CCmdUI* pCmdUI)
706 pCmdUI->SetCheck(true);
708 pCmdUI->SetCheck(false);
711 void CGeometryDoc::OnUpdateBUTTONTest7(CCmdUI* pCmdUI)
714 pCmdUI->SetCheck(true);
716 pCmdUI->SetCheck(false);
719 void CGeometryDoc::OnUpdateBUTTONTest8(CCmdUI* pCmdUI)
722 pCmdUI->SetCheck(true);
724 pCmdUI->SetCheck(false);
727 void CGeometryDoc::OnUpdateBUTTONTest9(CCmdUI* pCmdUI)
730 pCmdUI->SetCheck(true);
732 pCmdUI->SetCheck(false);
735 void CGeometryDoc::OnUpdateBUTTONTest10(CCmdUI* pCmdUI)
738 pCmdUI->SetCheck(true);
740 pCmdUI->SetCheck(false);
743 void CGeometryDoc::OnUpdateBUTTONTest11(CCmdUI* pCmdUI)
746 pCmdUI->SetCheck(true);
748 pCmdUI->SetCheck(false);
751 void CGeometryDoc::OnUpdateBUTTONTest12(CCmdUI* pCmdUI)
754 pCmdUI->SetCheck(true);
755 else pCmdUI->SetCheck(false);
758 void CGeometryDoc::OnUpdateBUTTONTest13(CCmdUI* pCmdUI)
761 pCmdUI->SetCheck(true);
763 pCmdUI->SetCheck(false);
766 void CGeometryDoc::OnUpdateBUTTONTest14(CCmdUI* pCmdUI)
769 pCmdUI->SetCheck(true);
771 pCmdUI->SetCheck(false);
774 void CGeometryDoc::OnUpdateBUTTONTest15(CCmdUI* pCmdUI)
777 pCmdUI->SetCheck(true);
779 pCmdUI->SetCheck(false);
782 void CGeometryDoc::OnUpdateBUTTONTest16(CCmdUI* pCmdUI)
785 pCmdUI->SetCheck(true);
787 pCmdUI->SetCheck(false);
790 void CGeometryDoc::OnUpdateBUTTONTest17(CCmdUI* pCmdUI)
793 pCmdUI->SetCheck(true);
795 pCmdUI->SetCheck(false);
798 void CGeometryDoc::OnUpdateBUTTONTest18(CCmdUI* pCmdUI)
801 pCmdUI->SetCheck(true);
803 pCmdUI->SetCheck(false);
806 void CGeometryDoc::OnUpdateBUTTONTest19(CCmdUI* pCmdUI)
809 pCmdUI->SetCheck(true);
811 pCmdUI->SetCheck(false);
814 void CGeometryDoc::OnUpdateBUTTONTest20(CCmdUI* pCmdUI)
817 pCmdUI->SetCheck(true);
819 pCmdUI->SetCheck(false);
822 void CGeometryDoc::OnUpdateBUTTONTest21(CCmdUI* pCmdUI)
825 pCmdUI->SetCheck(true);
827 pCmdUI->SetCheck(false);
830 void CGeometryDoc::OnUpdateBUTTONTest22(CCmdUI* pCmdUI)
833 pCmdUI->SetCheck(true);
835 pCmdUI->SetCheck(false);
838 void CGeometryDoc::OnUpdateBUTTONTest23(CCmdUI* pCmdUI)
841 pCmdUI->SetCheck(true);
843 pCmdUI->SetCheck(false);
846 void CGeometryDoc::OnUpdateBUTTONTest24(CCmdUI* pCmdUI)
849 pCmdUI->SetCheck(true);
851 pCmdUI->SetCheck(false);
854 void CGeometryDoc::OnUpdateBUTTONTest25(CCmdUI* pCmdUI)
857 pCmdUI->SetCheck(true);
859 pCmdUI->SetCheck(false);
862 void CGeometryDoc::OnUpdateBUTTONTest26(CCmdUI* pCmdUI)
865 pCmdUI->SetCheck(true);
867 pCmdUI->SetCheck(false);
870 void CGeometryDoc::OnUpdateBUTTONTest27(CCmdUI* pCmdUI)
873 pCmdUI->SetCheck(true);
875 pCmdUI->SetCheck(false);
878 void CGeometryDoc::OnUpdateBUTTONTest28(CCmdUI* pCmdUI)
881 pCmdUI->SetCheck(true);
883 pCmdUI->SetCheck(false);
886 void CGeometryDoc::OnUpdateBUTTONTest29(CCmdUI* pCmdUI)
889 pCmdUI->SetCheck(true);
891 pCmdUI->SetCheck(false);
894 void CGeometryDoc::OnUpdateBUTTONTest30(CCmdUI* pCmdUI)
897 pCmdUI->SetCheck(true);
899 pCmdUI->SetCheck(false);
902 void CGeometryDoc::OnUpdateBUTTONTest31(CCmdUI* pCmdUI)
905 pCmdUI->SetCheck(true);
907 pCmdUI->SetCheck(false);
910 void CGeometryDoc::OnUpdateBUTTONTest32(CCmdUI* pCmdUI)
913 pCmdUI->SetCheck(true);
915 pCmdUI->SetCheck(false);
918 void CGeometryDoc::OnUpdateBUTTONTest33(CCmdUI* pCmdUI)
921 pCmdUI->SetCheck(true);
923 pCmdUI->SetCheck(false);
926 void CGeometryDoc::OnUpdateBUTTONTest34(CCmdUI* pCmdUI)
929 pCmdUI->SetCheck(true);
931 pCmdUI->SetCheck(false);
934 void CGeometryDoc::OnUpdateBUTTONTest35(CCmdUI* pCmdUI)
937 pCmdUI->SetCheck(true);
939 pCmdUI->SetCheck(false);
942 void CGeometryDoc::OnUpdateBUTTONTest36(CCmdUI* pCmdUI)
945 pCmdUI->SetCheck(true);
947 pCmdUI->SetCheck(false);
950 void CGeometryDoc::OnUpdateBUTTONTest37(CCmdUI* pCmdUI)
953 pCmdUI->SetCheck(true);
955 pCmdUI->SetCheck(false);
958 void CGeometryDoc::OnUpdateBUTTONTest38(CCmdUI* pCmdUI)
961 pCmdUI->SetCheck(true);
963 pCmdUI->SetCheck(false);
966 void CGeometryDoc::OnUpdateBUTTONTest39(CCmdUI* pCmdUI)
969 pCmdUI->SetCheck(true);
971 pCmdUI->SetCheck(false);
974 void CGeometryDoc::OnUpdateBUTTONTest40(CCmdUI* pCmdUI)
977 pCmdUI->SetCheck(true);
979 pCmdUI->SetCheck(false);
982 void CGeometryDoc::OnUpdateBUTTONTest41(CCmdUI* pCmdUI)
985 pCmdUI->SetCheck(true);
987 pCmdUI->SetCheck(false);
990 void CGeometryDoc::OnUpdateBUTTONTest42(CCmdUI* pCmdUI)
993 pCmdUI->SetCheck(true);
995 pCmdUI->SetCheck(false);
998 void CGeometryDoc::OnUpdateBUTTONTest43(CCmdUI* pCmdUI)
1001 pCmdUI->SetCheck(true);
1003 pCmdUI->SetCheck(false);
1006 void CGeometryDoc::OnUpdateBUTTONTest44(CCmdUI* pCmdUI)
1009 pCmdUI->SetCheck(true);
1011 pCmdUI->SetCheck(false);
1014 void CGeometryDoc::OnUpdateBUTTONTest45(CCmdUI* pCmdUI)
1017 pCmdUI->SetCheck(true);
1019 pCmdUI->SetCheck(false);
1022 void CGeometryDoc::OnUpdateBUTTONTest46(CCmdUI* pCmdUI)
1025 pCmdUI->SetCheck(true);
1027 pCmdUI->SetCheck(false);
1030 void CGeometryDoc::OnUpdateBUTTONTest47(CCmdUI* pCmdUI)
1033 pCmdUI->SetCheck(true);
1035 pCmdUI->SetCheck(false);
1038 void CGeometryDoc::OnUpdateBUTTONTest48(CCmdUI* pCmdUI)
1041 pCmdUI->SetCheck(true);
1043 pCmdUI->SetCheck(false);
1046 void CGeometryDoc::OnUpdateBUTTONTest49(CCmdUI* pCmdUI)
1049 pCmdUI->SetCheck(true);
1051 pCmdUI->SetCheck(false);
1054 void CGeometryDoc::OnUpdateBUTTONTest50(CCmdUI* pCmdUI)
1057 pCmdUI->SetCheck(true);
1059 pCmdUI->SetCheck(false);
1062 void CGeometryDoc::OnCloseDocument()
1064 // TODO: Add your specialized code here and/or call the base class
1065 CDocument::OnCloseDocument();
1068 void CGeometryDoc::OnCreateSol()
1070 // TODO: Add your command handler code here
1071 // Creation d'un sol
1072 CFileDialog dlg (TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
1073 L"Points Files (*.dat)|*.dat; |All Files (*.*)|*.*||", NULL);
1075 CString anOCCTDataPathValue;
1076 anOCCTDataPathValue.GetEnvironmentVariable(L"CSF_OCCTDataPath");
1077 CString initdir = (anOCCTDataPathValue + L"\\occ\\SurfaceFromPoints");
1079 dlg.m_ofn.lpstrInitialDir = initdir;
1081 if (dlg.DoModal() == IDOK)
1083 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
1084 CString filename = dlg.GetPathName();
1087 std::istream in(&fic);
1088 if (!fic.open (filename, std::ios::in))
1089 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Unable to open file", L"CasCade Error", MB_ICONERROR);
1091 TColgp_SequenceOfXYZ seqOfXYZ;
1093 Standard_Integer nbPnt=0;
1094 Standard_Real x,y,z;
1098 while (!in.fail()|| !in.eof())
1100 if (in >> x && in >> y && in >> z){
1105 seqOfXYZ.Append(pntXYZ);
1106 BRepBuilderAPI_MakeVertex V(gp_Pnt(x, y, z));
1107 B.Add(C,V.Vertex());
1111 Handle(AIS_Shape) anAISCompound = new AIS_Shape(C);
1112 myAISContext->Display(anAISCompound, Standard_False);
1116 sol.Build(seqOfXYZ);
1118 if (sol.IsDone() == Standard_True)
1120 Handle(Geom_BSplineSurface) GeomSol = sol.Surface();
1121 TopoDS_Face aface = BRepBuilderAPI_MakeFace(GeomSol, Precision::Confusion());
1122 if (!BRepAlgo::IsValid(aface))
1123 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : The plate surface is not valid!", L"CasCade Error", MB_ICONERROR);
1124 Handle(AIS_Shape) anAISShape=new AIS_Shape(aface);
1125 myAISContext->Display(anAISShape, Standard_False);
1129 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Computation has failed", L"CasCade Error", MB_ICONERROR);
1133 /*********************************************************************************************
1134 ********************** S I M P L I F Y *****************************************************
1135 *********************************************************************************************/
1137 //================================================================
1138 // Function : fixParam
1139 // Purpose : assigns a finite value to theParam if it's infinite
1140 // (equal to +- Precision::Infinite())
1141 //================================================================
1142 static Standard_Boolean fixParam(Standard_Real& theParam)
1144 Standard_Boolean aResult = Standard_False;
1145 if (Precision::IsNegativeInfinite(theParam))
1147 theParam = -MAX_PARAM;
1148 aResult = Standard_True;
1150 if (Precision::IsPositiveInfinite(theParam))
1152 theParam = MAX_PARAM;
1153 aResult = Standard_True;
1159 void CGeometryDoc::OnSimplify()
1161 CString anOCCTDataPathValue;
1162 anOCCTDataPathValue.GetEnvironmentVariable(L"CSF_OCCTDataPath");
1163 CString initfile = (anOCCTDataPathValue + L"\\occ\\shell1.brep");
1165 std::filebuf aFileBuf;
1166 std::istream aStream (&aFileBuf);
1167 if (!aFileBuf.open (initfile, std::ios::in))
1169 initfile += L" was not found. The sample can not be shown.";
1170 myCResultDialog.SetText (initfile);
1174 TopoDS_Shape aShape;
1176 BRepTools::Read (aShape, aStream, aBld);
1177 if (aShape.IsNull())
1179 initfile += L" is invalid file. The sample can not be shown.";
1180 myCResultDialog.SetText(initfile);
1183 myAISContext->SetDisplayMode(AIS_Shaded, Standard_True);
1187 void CGeometryDoc::simplify(const TopoDS_Shape& aShape)
1189 myCResultDialog.SetTitle("Simplify Face");
1190 myCResultDialog.SetText(" TopoDS_Shape aShape;\n"
1192 " // initialize aShape\n"
1195 " // define parameter triangulation\n"
1196 " Standard_Real aDeflection = 0.1;\n"
1198 " // removes all the triangulations of the faces ,\n"
1199 " //and all the polygons on the triangulations of the edges\n"
1200 " BRepTools::Clean(aShape);\n"
1201 " // adds a triangulation of the shape aShape with the deflection aDeflection\n"
1202 " BRepMesh::Mesh(aShape,aDeflection);\n"
1204 " Standard_Integer aIndex = 1, nbNodes = 0;\n"
1206 " // define two sequence of points\n"
1207 " TColgp_SequenceOfPnt aPoints, aPoints1;\n"
1209 " // triangulation\n"
1210 " for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())\n"
1212 " TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());\n"
1213 " TopLoc_Location aLocation;\n"
1215 " // takes the triangulation of the face aFace\n"
1216 " Handle(Poly_Triangulation) aTr = BRep_Tool::Triangulation(aFace,aLocation);\n"
1218 " if(!aTr.IsNull())\n"
1220 " // takes the array of nodes for this triangulation\n"
1221 " const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); \n"
1222 " nbNodes = aNodes.Length();\n"
1224 " for( Standard_Integer i = 1; i <= nbNodes; i++)\n"
1226 " // create seguence of node points in absolute coordinate system\n"
1227 " gp_Pnt aPnt = aNodes(i).Transformed(aLocation);\n"
1228 " aPoints.Append(aPnt);\n"
1234 " // remove double points\n"
1235 " nbNodes = aPoints.Length();\n"
1236 " for( Standard_Integer i = 1; i <= nbNodes; i++)\n"
1238 " gp_Pnt aPi = aPoints(i);\n"
1239 " for( Standard_Integer j = i + 1; j < nbNodes; j++)\n"
1241 " gp_Pnt aPj = aPoints(j);\n"
1242 " if(!aPi.IsEqual(aPj,0.9))\n"
1245 " if(aIndex == j - 1)\n"
1246 " aPoints1.Append(aPi);\n"
1248 " aIndex = i + 1;\n"
1251 " // find max point\n"
1253 " gp_Pnt aPntMax = aPoints1(1);\n"
1254 " nbNodes = aPoints1.Length();\n"
1255 " for(i = 2; i <= nbNodes; i++)\n"
1257 " if(aPoints1(i).X() > aPntMax.X())\n"
1260 " aPntMax = aPoints1(aIndex); \n"
1264 " // clear seguence\n"
1265 " aPoints.Clear();\n"
1267 " Standard_Integer nbLeftNodes = nbNodes;\n"
1269 " // ascending sort - fill aPoints with ascending \n"
1270 " // by X coordinate points from aPoints1\n"
1271 " for(i = 1; i < nbNodes; i++)\n"
1273 " Standard_Real aMin = aPntMax.X();\n"
1275 " for( Standard_Integer j = 1; j <= nbLeftNodes; j++)\n"
1277 " if(aPoints1(j).X() < aMin)\n"
1279 " aMin = aPoints1(j).X();\n"
1283 " aPoints.Append(aPoints1(aIndex));\n"
1284 " aPoints1.Remove(aIndex);\n"
1285 " nbLeftNodes = aPoints1.Length();\n"
1287 " aPoints.Append(aPntMax);\n"
1289 " // define parameters GeomPlate_BuildPlateSurface\n"
1290 " Standard_Integer Degree = 3;\n"
1291 " Standard_Integer NbPtsOnCur = 10;\n"
1292 " Standard_Integer NbIter = 3;\n"
1293 " Standard_Integer Order = 0;\n"
1294 " Standard_Integer MaxSeg = 9;\n"
1295 " Standard_Integer MaxDegree = 5;\n"
1296 " Standard_Real dmax, anApproxTol = 0.001;\n"
1297 " Standard_Real aConstrTol = Precision::Confusion();\n"
1299 " // define object BuildPlateSurface\n"
1300 " GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);\n"
1302 " // add point constraints to GeomPlate_BuildPlateSurface object\n"
1303 " nbNodes = aPoints.Length();\n"
1304 " for (i = 1; i <= nbNodes; i++)\n"
1305 " BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));\n"
1307 " BPSurf.Perform();\n"
1309 " // make PlateSurface\n"
1310 " Handle(GeomPlate_Surface) PSurf;\n"
1311 " Handle(Geom_Surface) aSurf;\n"
1313 " if (BPSurf.IsDone())\n"
1315 " PSurf = BPSurf.Surface();\n"
1317 " // define parameter approximation\n"
1318 " dmax = Max(0.01,10*BPSurf.G0Error());\n"
1320 " // make approximation\n"
1321 " GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);\n"
1322 " aSurf = Mapp.Surface();\n"
1327 " ShapeAnalysis_FreeBounds aFreeBounds(aShape, Standard_False, Standard_True);\n"
1328 " TopoDS_Compound aClosedWires = aFreeBounds.GetClosedWires();\n"
1329 " TopTools_IndexedMapOfShape aWires;\n"
1330 " TopExp::MapShapes(aClosedWires, TopAbs_WIRE, aWires);\n"
1331 " TopoDS_Wire aWire;\n"
1332 " Standard_Integer nbWires = aWires.Extent();\n"
1334 " aWire = TopoDS::Wire(aWires(1));\n"
1338 " BRep_Builder B;\n"
1339 " TopoDS_Face aFace;\n"
1340 " B.MakeFace(aFace, aSurf, Precision::Confusion());\n"
1341 " B.Add(aFace, aWire);\n"
1342 " Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape(aFace);\n"
1343 " sfs->Perform();\n"
1344 " TopoDS_Shape aFixedFace = sfs->Shape();\n"
1345 " if (aFixedFace.IsNull()) \n"
1348 // define parameter triangulation
1349 Standard_Real aDeflection = 0.1;
1351 // removes all the triangulations of the faces ,
1352 //and all the polygons on the triangulations of the edges
1353 BRepTools::Clean(aShape);
1354 // adds a triangulation of the shape aShape with the deflection aDeflection
1355 BRepMesh_IncrementalMesh(aShape,aDeflection);
1357 Standard_Integer aIndex = 1, nbNodes = 0;
1359 // define two sequence of points
1360 TColgp_SequenceOfPnt aPoints, aPoints1;
1363 for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())
1365 TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());
1366 TopLoc_Location aLocation;
1368 // takes the triangulation of the face aFace
1369 Handle(Poly_Triangulation) aTr = BRep_Tool::Triangulation(aFace,aLocation);
1373 // takes the array of nodes for this triangulation
1374 const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
1375 nbNodes = aNodes.Length();
1377 for( Standard_Integer i = 1; i <= nbNodes; i++)
1379 // create seguence of node points in absolute coordinate system
1380 gp_Pnt aPnt = aNodes(i).Transformed(aLocation);
1381 aPoints.Append(aPnt);
1387 // remove double points
1388 nbNodes = aPoints.Length();
1390 for( i = 1; i <= nbNodes; i++)
1392 gp_Pnt aPi = aPoints(i);
1394 for( j = i + 1; j < nbNodes; j++)
1396 gp_Pnt aPj = aPoints(j);
1397 if(!aPi.IsEqual(aPj,0.9))
1401 aPoints1.Append(aPi);
1408 gp_Pnt aPntMax = aPoints1(1);
1409 nbNodes = aPoints1.Length();
1410 for(i = 2; i <= nbNodes; i++)
1412 if(aPoints1(i).X() > aPntMax.X())
1415 aPntMax = aPoints1(aIndex);
1422 Standard_Integer nbLeftNodes = nbNodes;
1424 // ascending sort - fill aPoints with ascending
1425 // by X coordinate points from aPoints1
1426 for(i = 1; i < nbNodes; i++)
1428 Standard_Real aMin = aPntMax.X();
1430 for( Standard_Integer j = 1; j <= nbLeftNodes; j++)
1432 if(aPoints1(j).X() < aMin)
1434 aMin = aPoints1(j).X();
1438 aPoints.Append(aPoints1(aIndex));
1439 aPoints1.Remove(aIndex);
1440 nbLeftNodes = aPoints1.Length();
1442 aPoints.Append(aPntMax);
1444 // define parameters GeomPlate_BuildPlateSurface
1445 Standard_Integer Degree = 3;
1446 Standard_Integer NbPtsOnCur = 10;
1447 Standard_Integer NbIter = 3;
1448 Standard_Integer Order = 0;
1449 Standard_Integer MaxSeg = 9;
1450 Standard_Integer MaxDegree = 5;
1451 Standard_Real dmax, anApproxTol = 0.001;
1452 Standard_Real aConstrTol = Precision::Confusion();
1454 // define object BuildPlateSurface
1455 GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);
1457 // add point constraints to GeomPlate_BuildPlateSurface object
1458 nbNodes = aPoints.Length();
1459 for (i = 1; i <= nbNodes; i++)
1460 BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));
1464 // make PlateSurface
1465 Handle(GeomPlate_Surface) PSurf;
1466 Handle(Geom_Surface) aSurf;
1468 if (BPSurf.IsDone())
1470 PSurf = BPSurf.Surface();
1472 // define parameter approximation
1473 dmax = Max(0.01,10*BPSurf.G0Error());
1475 // make approximation
1476 GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);
1477 aSurf = Mapp.Surface();
1482 ShapeAnalysis_FreeBounds aFreeBounds(aShape, Standard_False, Standard_True);
1483 TopoDS_Compound aClosedWires = aFreeBounds.GetClosedWires();
1484 TopTools_IndexedMapOfShape aWires;
1485 TopExp::MapShapes(aClosedWires, TopAbs_WIRE, aWires);
1487 Standard_Integer nbWires = aWires.Extent();
1489 aWire = TopoDS::Wire(aWires(1));
1495 B.MakeFace(aFace, aSurf, Precision::Confusion());
1496 B.Add(aFace, aWire);
1497 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape(aFace);
1499 TopoDS_Shape aFixedFace = sfs->Shape();
1500 if (aFixedFace.IsNull())
1503 // output surface, make it half transparent
1504 Handle(AIS_InteractiveObject) aSurfIO = drawSurface(
1505 aSurf, Quantity_NOC_LEMONCHIFFON3, Standard_False);
1506 aSurfIO->SetTransparency(0.5);
1507 myAISContext->Display(aSurfIO,Standard_False);
1510 if(WAIT_A_LITTLE) return;
1513 for(i = 1; i <= nbNodes; i++)
1514 drawPoint(aPoints(i));
1516 if(WAIT_A_LITTLE) return;
1518 // output resulting face
1519 drawShape(aFixedFace);
1522 Handle(AIS_InteractiveObject) CGeometryDoc::drawSurface
1523 (const Handle(Geom_Surface)& theSurface,
1524 const Quantity_Color& theColor,
1525 const Standard_Boolean toDisplay)
1527 Standard_Real u1, u2, v1, v2;
1528 theSurface->Bounds(u1,u2,v1,v2);
1534 Handle(AIS_Shape) aGraphicSurface =
1535 new AIS_Shape(BRepBuilderAPI_MakeFace (theSurface, u1, u2, v1, v2, Precision::Confusion()));
1537 myAISContext->SetMaterial(aGraphicSurface, Graphic3d_NameOfMaterial_Plastified, toDisplay);
1538 myAISContext->SetColor(aGraphicSurface, theColor, toDisplay);
1543 myAISContext->Display (aGraphicSurface, Standard_False);
1547 myAISContext->Display (aGraphicSurface, Standard_True);
1550 return aGraphicSurface;
1553 Standard_Boolean CGeometryDoc::WaitForInput (unsigned long aMilliSeconds)
1555 //::WaitForSingleObject(::CreateEvent (NULL, FALSE, FALSE, NULL), aMilliSeconds);
1556 if (::MsgWaitForMultipleObjects(0, NULL, FALSE, aMilliSeconds,
1557 QS_KEY | QS_MOUSEBUTTON) != WAIT_TIMEOUT)
1560 if (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
1562 if (msg.message == WM_KEYUP)
1564 ::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE);
1565 return WaitForInput (aMilliSeconds);
1568 return Standard_True;
1571 return Standard_False;
1574 Handle(AIS_Point) CGeometryDoc::drawPoint
1575 (const gp_Pnt& aPnt,
1576 const Quantity_Color& theColor,
1577 const Standard_Boolean toDisplay)
1579 Handle(AIS_Point) aGraphicPoint = new AIS_Point (new Geom_CartesianPoint(aPnt));
1581 myAISContext->SetColor (aGraphicPoint, theColor, toDisplay);
1584 myAISContext->Display (aGraphicPoint, Standard_True);
1585 //COCCDemoDoc::Fit();
1588 return aGraphicPoint;
1591 Handle(AIS_Shape) CGeometryDoc::drawShape
1592 (const TopoDS_Shape& theShape,
1593 const Graphic3d_NameOfMaterial theMaterial,
1594 const Standard_Boolean toDisplay)
1596 Handle(AIS_Shape) aGraphicShape = new AIS_Shape(theShape);
1598 myAISContext->SetMaterial(aGraphicShape, theMaterial, toDisplay);
1603 myAISContext->Display (aGraphicShape, Standard_False);
1607 myAISContext->Display (aGraphicShape, Standard_True);
1610 return aGraphicShape;