dd9c3be4fa2ae1181554363c7fbbcc0755460d33
[occt.git] / src / BRepMesh / BRepMesh_ModelBuilder.cxx
1 // Created on: 2016-04-07
2 // Copyright (c) 2016 OPEN CASCADE SAS
3 // Created by: Oleg AGASHIN
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BRepMesh_ModelBuilder.hxx>
17 #include <BRepMeshData_Model.hxx>
18 #include <BRepMesh_ShapeVisitor.hxx>
19 #include <BRepMesh_ShapeTool.hxx>
20 #include <IMeshTools_ShapeExplorer.hxx>
21 #include <Standard_ErrorHandler.hxx>
22
23 #include <Bnd_Box.hxx>
24 #include <BRepBndLib.hxx>
25
26 //=======================================================================
27 // Function: Constructor
28 // Purpose : 
29 //=======================================================================
30 BRepMesh_ModelBuilder::BRepMesh_ModelBuilder ()
31 {
32 }
33
34 //=======================================================================
35 // Function: Destructor
36 // Purpose : 
37 //=======================================================================
38 BRepMesh_ModelBuilder::~BRepMesh_ModelBuilder ()
39 {
40 }
41
42 //=======================================================================
43 // Function: Perform
44 // Purpose : 
45 //=======================================================================
46 Handle (IMeshData_Model) BRepMesh_ModelBuilder::Perform (
47   const TopoDS_Shape&          theShape,
48   const IMeshTools_Parameters& theParameters)
49 {
50   ClearStatus ();
51
52   Handle (BRepMeshData_Model) aModel;
53   try
54   {
55     OCC_CATCH_SIGNALS
56
57     Bnd_Box aBox;
58     BRepBndLib::Add (theShape, aBox, Standard_False);
59
60     if (!aBox.IsVoid ())
61     {
62       // Build data model for further processing.
63       aModel = new BRepMeshData_Model (theShape);
64
65       if (theParameters.Relative)
66       {
67         Standard_Real aMaxSize;
68         BRepMesh_ShapeTool::BoxMaxDimension (aBox, aMaxSize);
69         aModel->SetMaxSize(aMaxSize);
70       }
71       else
72       {
73         aModel->SetMaxSize(Max(theParameters.Deflection,
74                                theParameters.DeflectionInterior));
75       }
76
77       Handle (IMeshTools_ShapeVisitor) aVisitor =
78         new BRepMesh_ShapeVisitor (aModel);
79
80       IMeshTools_ShapeExplorer aExplorer (theShape);
81       aExplorer.Accept (aVisitor);
82       SetStatus (Message_Done1);
83     }
84     else
85     {
86       SetStatus(Message_Fail1);
87     }
88   }
89   catch (Standard_Failure&)
90   {
91     SetStatus (Message_Fail2);
92   }
93
94   return aModel;
95 }