0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepFill / BRepFill_ACRLaw.cxx
1 // Created on: 1998-09-01
2 // Created by: Stephanie Humeau
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Approx_CurvlinFunc.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepFill.hxx>
21 #include <BRepFill_ACRLaw.hxx>
22 #include <BRepTools_WireExplorer.hxx>
23 #include <Geom_Curve.hxx>
24 #include <Geom_TrimmedCurve.hxx>
25 #include <GeomAdaptor_HCurve.hxx>
26 #include <GeomFill_HArray1OfLocationLaw.hxx>
27 #include <GeomFill_LocationGuide.hxx>
28 #include <GeomFill_LocationLaw.hxx>
29 #include <Standard_Type.hxx>
30 #include <TopExp.hxx>
31 #include <TopoDS.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Wire.hxx>
34 #include <TopTools_HArray1OfShape.hxx>
35
36 BRepFill_ACRLaw::BRepFill_ACRLaw(const TopoDS_Wire& Path,
37                                  const Handle(GeomFill_LocationGuide)& theLaw)
38 {
39   Init(Path);
40
41 // calculate the nb of edge of the path
42   BRepTools_WireExplorer wexp;
43   Standard_Integer NbEdge = 0; 
44   for (wexp.Init(myPath); wexp.More(); wexp.Next()) NbEdge++;
45
46 // tab to memorize ACR for each edge
47   OrigParam = new (TColStd_HArray1OfReal)(0,NbEdge);
48   TColStd_Array1OfReal Orig (0,NbEdge);
49   BRepFill::ComputeACR(Path, Orig);
50
51   Standard_Integer ipath;
52   TopAbs_Orientation Or;
53 // Class BRep_Tool without fields and without Constructor :
54 //  BRep_Tool B;
55   TopoDS_Edge E;
56   Handle(Geom_Curve) C;
57   Handle(GeomAdaptor_HCurve) AC;
58   Standard_Real First, Last;
59
60 // return ACR of edges of the trajectory
61   OrigParam->SetValue(0,0); 
62   for (ipath=1;ipath<=NbEdge;ipath++)
63     OrigParam->SetValue(ipath, Orig(ipath));
64
65 // process each edge of the trajectory
66   for (ipath=0, wexp.Init(myPath); 
67        wexp.More(); wexp.Next()) {
68     E = wexp.Current();
69 //    if (!B.Degenerated(E)) {
70     if (!BRep_Tool::Degenerated(E)) {
71       ipath++;
72       myEdges->SetValue(ipath, E);
73       C = BRep_Tool::Curve(E,First,Last);
74       Or = E.Orientation();
75       if (Or == TopAbs_REVERSED) {
76         Handle(Geom_TrimmedCurve) CBis = 
77           new (Geom_TrimmedCurve) (C, First, Last);
78         CBis->Reverse(); // To avoid damaging the topology
79         C = CBis;
80         First =  C->FirstParameter();
81         Last  =  C->LastParameter();
82       }
83       AC = new  (GeomAdaptor_HCurve) (C, First, Last);
84
85       // Set the parameters for the case multi-edges
86       Standard_Real t1 = OrigParam->Value(ipath-1);
87       Standard_Real t2 = OrigParam->Value(ipath);
88       Handle(GeomFill_LocationGuide) Loc;
89       Loc = Handle(GeomFill_LocationGuide)::DownCast(theLaw);
90       Loc->SetOrigine(t1,t2);
91
92       myLaws->SetValue(ipath, Loc->Copy());
93       myLaws->ChangeValue(ipath)->SetCurve(AC);
94     }
95   }
96 }