Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-06-04 |
2 | // Created by: Jean Yves LEBEY | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
973c2be1 | 8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
17 | #include <TopOpeBRepDS_TKI.hxx> | |
18 | #include <TopOpeBRepDS_HDataStructure.hxx> | |
19 | #include <stdlib.h> | |
20 | #include <TopOpeBRep_define.hxx> | |
21 | ||
091232ba | 22 | typedef TopOpeBRepDS_ListOfInterference* BOA_t; |
7fd59977 | 23 | |
091232ba RL |
24 | static int compll(const void* v1, const void* v2) { |
25 | BOA_t l1 = *(BOA_t*)v1; | |
26 | BOA_t l2 = *(BOA_t*)v2; | |
7fd59977 | 27 | if (l1->Extent() == 0) return (0); |
28 | else if (l2->Extent() == 0) return (0); | |
29 | ||
091232ba RL |
30 | Handle(TopOpeBRepDS_CurvePointInterference) i1 = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(l1->First()); |
31 | if (i1.IsNull()) | |
32 | return 0; | |
33 | Handle(TopOpeBRepDS_CurvePointInterference) i2 = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(l2->First()); | |
34 | if (i2.IsNull()) | |
35 | return 0; | |
7fd59977 | 36 | Standard_Real p1 = i1->Parameter(); |
37 | Standard_Real p2 = i2->Parameter(); | |
38 | if (p1 < p2) return (-1); | |
39 | else if (p1 > p2) return (1); | |
091232ba | 40 | return 0; |
7fd59977 | 41 | } |
42 | ||
091232ba | 43 | static void BREP_sortonparameter2(TopOpeBRepDS_ListOfInterference& LOI) |
7fd59977 | 44 | { |
091232ba RL |
45 | TopOpeBRepDS_TKI tki; |
46 | tki.FillOnGeometry(LOI); | |
47 | Standard_Integer ng=0; | |
48 | for(tki.Init();tki.More();tki.Next()) | |
49 | ng++; | |
50 | size_t sng=(size_t)ng; | |
51 | size_t sad=sizeof(BOA_t); | |
52 | BOA_t* T = (BOA_t*)Standard::Allocate (sng*sad); | |
53 | TopOpeBRepDS_Kind K; | |
54 | Standard_Integer G, j=0; | |
55 | for(tki.Init();tki.More();tki.Next(),j++) | |
56 | T[j]= &(tki.ChangeValue(K,G)); | |
7fd59977 | 57 | qsort(T,sng,sad,compll); |
091232ba RL |
58 | LOI.Clear(); |
59 | for(j=0;j<ng;j++) | |
60 | { | |
61 | TopOpeBRepDS_ListOfInterference& l=*T[j]; | |
62 | LOI.Append(l); | |
63 | } | |
64 | Standard::Free(T); | |
7fd59977 | 65 | } |
66 | ||
67 | Standard_EXPORT void BREP_sortonparameter(const Handle(TopOpeBRepDS_HDataStructure)& HDS) | |
68 | { | |
69 | TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS(); | |
70 | Standard_Integer i=1, n=HDS->NbShapes(); | |
71 | for (; i<=n; i++) { | |
72 | const TopoDS_Shape& s = HDS->Shape(i); | |
73 | if (s.ShapeType() != TopAbs_EDGE) continue; | |
74 | TopOpeBRepDS_ListOfInterference& LOI = BDS.ChangeShapeInterferences(s); | |
75 | BREP_sortonparameter2(LOI); | |
76 | } | |
77 | } |