0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / TopOpeBRep / TopOpeBRep_sort.cxx
CommitLineData
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//
d5f74e42 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
973c2be1 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>
ec357c5c 21#include <TopOpeBRepDS_CurvePointInterference.hxx>
7fd59977 22
091232ba 23typedef TopOpeBRepDS_ListOfInterference* BOA_t;
7fd59977 24
091232ba
RL
25static int compll(const void* v1, const void* v2) {
26 BOA_t l1 = *(BOA_t*)v1;
27 BOA_t l2 = *(BOA_t*)v2;
7fd59977 28 if (l1->Extent() == 0) return (0);
29 else if (l2->Extent() == 0) return (0);
30
091232ba
RL
31 Handle(TopOpeBRepDS_CurvePointInterference) i1 = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(l1->First());
32 if (i1.IsNull())
33 return 0;
34 Handle(TopOpeBRepDS_CurvePointInterference) i2 = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(l2->First());
35 if (i2.IsNull())
36 return 0;
7fd59977 37 Standard_Real p1 = i1->Parameter();
38 Standard_Real p2 = i2->Parameter();
39 if (p1 < p2) return (-1);
40 else if (p1 > p2) return (1);
091232ba 41 return 0;
7fd59977 42}
43
091232ba 44static void BREP_sortonparameter2(TopOpeBRepDS_ListOfInterference& LOI)
7fd59977 45{
091232ba
RL
46 TopOpeBRepDS_TKI tki;
47 tki.FillOnGeometry(LOI);
48 Standard_Integer ng=0;
49 for(tki.Init();tki.More();tki.Next())
50 ng++;
51 size_t sng=(size_t)ng;
52 size_t sad=sizeof(BOA_t);
53 BOA_t* T = (BOA_t*)Standard::Allocate (sng*sad);
54 TopOpeBRepDS_Kind K;
55 Standard_Integer G, j=0;
56 for(tki.Init();tki.More();tki.Next(),j++)
57 T[j]= &(tki.ChangeValue(K,G));
7fd59977 58 qsort(T,sng,sad,compll);
091232ba
RL
59 LOI.Clear();
60 for(j=0;j<ng;j++)
61 {
62 TopOpeBRepDS_ListOfInterference& l=*T[j];
63 LOI.Append(l);
64 }
65 Standard::Free(T);
7fd59977 66}
67
68Standard_EXPORT void BREP_sortonparameter(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
69{
70 TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
71 Standard_Integer i=1, n=HDS->NbShapes();
72 for (; i<=n; i++) {
73 const TopoDS_Shape& s = HDS->Shape(i);
74 if (s.ShapeType() != TopAbs_EDGE) continue;
75 TopOpeBRepDS_ListOfInterference& LOI = BDS.ChangeShapeInterferences(s);
76 BREP_sortonparameter2(LOI);
77 }
78}