7fd59977 |
1 | // File: TopOpeBRep_sort.cxx |
2 | // Created: Thu Jun 4 17:58:30 1998 |
3 | // Author: Jean Yves LEBEY |
4 | // <jyl@langdox.paris1.matra-dtv.fr> |
5 | |
6 | #include <TopOpeBRepDS_TKI.hxx> |
7 | #include <TopOpeBRepDS_HDataStructure.hxx> |
8 | #include <stdlib.h> |
9 | #include <TopOpeBRep_define.hxx> |
10 | |
11 | typedef Standard_Address BOA_t; |
12 | |
13 | int compll(const void* v1, const void* v2) { |
14 | const TopOpeBRepDS_ListOfInterference* l1 = (const TopOpeBRepDS_ListOfInterference*)(*((long int*)v1)); |
15 | const TopOpeBRepDS_ListOfInterference* l2 = (const TopOpeBRepDS_ListOfInterference*)(*((long int*)v2)); |
16 | if (l1->Extent() == 0) return (0); |
17 | else if (l2->Extent() == 0) return (0); |
18 | |
19 | Handle(TopOpeBRepDS_CurvePointInterference) i1 = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(l1->First()); if (i1.IsNull()) return (0); |
20 | Handle(TopOpeBRepDS_CurvePointInterference) i2 = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(l2->First()); if (i2.IsNull()) return (0); |
21 | Standard_Real p1 = i1->Parameter(); |
22 | Standard_Real p2 = i2->Parameter(); |
23 | if (p1 < p2) return (-1); |
24 | else if (p1 > p2) return (1); |
25 | else return (0); |
26 | return (0); |
27 | } |
28 | |
29 | Standard_EXPORT void BREP_sortonparameter2(TopOpeBRepDS_ListOfInterference& LOI) |
30 | { |
31 | TopOpeBRepDS_TKI tki;tki.FillOnGeometry(LOI); |
32 | Standard_Integer ng=0; for(tki.Init();tki.More();tki.Next()) ng++; |
33 | size_t sng=(size_t)ng;size_t sad=sizeof(BOA_t); |
34 | BOA_t* T = (BOA_t*)malloc((size_t)(sng*sad));TopOpeBRepDS_Kind K;Standard_Integer G;Standard_Integer j=0; |
35 | for(tki.Init();tki.More();tki.Next(),j++) T[j]=(BOA_t)&(tki.Value(K,G)); |
36 | qsort(T,sng,sad,compll); |
37 | LOI.Clear();for(j=0;j<ng;j++) {TopOpeBRepDS_ListOfInterference& l=*((TopOpeBRepDS_ListOfInterference*)T[j]);LOI.Append(l);} |
38 | free(T); |
39 | } |
40 | |
41 | Standard_EXPORT void BREP_sortonparameter(const Handle(TopOpeBRepDS_HDataStructure)& HDS) |
42 | { |
43 | TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS(); |
44 | Standard_Integer i=1, n=HDS->NbShapes(); |
45 | for (; i<=n; i++) { |
46 | const TopoDS_Shape& s = HDS->Shape(i); |
47 | if (s.ShapeType() != TopAbs_EDGE) continue; |
48 | TopOpeBRepDS_ListOfInterference& LOI = BDS.ChangeShapeInterferences(s); |
49 | BREP_sortonparameter2(LOI); |
50 | } |
51 | } |