0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / Interface / Interface_ParamSet.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14//szv#4 S4163
7fd59977 15
42cf5bc1 16#include <Interface_FileParameter.hxx>
17#include <Interface_ParamList.hxx>
18#include <Interface_ParamSet.hxx>
19#include <Standard_OutOfRange.hxx>
20#include <Standard_Type.hxx>
7fd59977 21
25e59720 22IMPLEMENT_STANDARD_RTTIEXT(Interface_ParamSet,Standard_Transient)
92efcf78 23
7fd59977 24Interface_ParamSet::Interface_ParamSet (const Standard_Integer nres, const Standard_Integer )//nst)
25{
26 thelist = new Interface_ParamList;// (nst,nst+nres+2);
27 themxpar = nres;
28 thenbpar = 0;
29 thelnval = 0;
30 thelnres = 100; // *20; // 10 caracteres par Param (\0 inclus) : raisonnable
31 theval = new char[thelnres]; //szv#4:S4163:12Mar99 `thelnres+1` chars was wrong
32}
33
34
35// Append(CString) : Gestion des caracteres selon <lnval>
36// Si lnval < 0, ParamSet passif, memoire geree de l exterieur, ParamSet
37// se contente de s y referer
38// Sinon, recopie dans une page locale
39
40Standard_Integer Interface_ParamSet::Append (const Standard_CString val, const Standard_Integer lnval,
41 const Interface_ParamType typ, const Standard_Integer nument)
42{
43 // Ici, gestion locale de String
44 thenbpar ++;
45 if (thenbpar > themxpar) {
46 thenext = new Interface_ParamSet (themxpar,1);
47 return (thenbpar + thenext->Append(val,lnval,typ,nument));
48 }
49 else if (lnval < 0) {
50 // .. Gestion externe des caracteres ..
51 Interface_FileParameter& FP = thelist->ChangeValue(thenbpar);
52 FP.Init(val,typ);
53 if (nument != 0) FP.SetEntityNumber(nument);
54 }
55 else {
56 // .. Gestion locale des caracteres ..
57 Standard_Integer i;
58 if (thelnval + lnval + 1 > thelnres) {
59 // Reservation de caracteres insuffisante : d abord augmenter
7dc9e047 60 Standard_Integer newres = (Standard_Integer)(thelnres*2 + lnval);
7fd59977 61 char* newval = new char[newres];
62 for (i = 0; i < thelnval; i++)
63 newval[i] = theval[i]; //szv#4:S4163:12Mar99 `<= thelnres` was wrong
64 // et cepatou : il faut realigner les Params deja enregistres sur
65 // l ancienne reservation de caracteres ...
66 //Standard_Integer delta = (Standard_Integer) (newval - theval);
67 // difference a appliquer
68 char* poldVal = &theval[0];
69 char* pnewVal= &newval[0];
70 for (i = 1; i < thenbpar; i ++) {
71 Interface_FileParameter& OFP = thelist->ChangeValue(i);
72 Interface_ParamType otyp = OFP.ParamType();
73 char* oval = (char*)OFP.CValue();
74 Standard_Integer delta = (Standard_Integer) (oval - poldVal);
75 //if (oval < theval || oval >= (theval+thelnres))
76 // continue; //hors reserve //szv#4:S4163:12Mar99 `oval >` was wrong
77 Standard_Integer onum = OFP.EntityNumber();
78 OFP.Init(pnewVal+delta,otyp); // et voila; on remet dans la boite
79 if (onum != 0) OFP.SetEntityNumber(onum);
80 }
81 // Enteriner la nouvelle reservation
82 delete [] theval;
83 theval = newval;
84 thelnres = newres;
85 }
86 // Enregistrer ce parametre
87 for (i = 0; i < lnval; i ++) theval[thelnval + i] = val[i];
88 theval[thelnval+lnval] = '\0';
89
90 Interface_FileParameter& FP = thelist->ChangeValue(thenbpar);
91 FP.Init(&theval[thelnval],typ);
92 if (nument != 0) FP.SetEntityNumber(nument);
7dc9e047 93 thelnval += (Standard_Integer)(lnval+1);
7fd59977 94 }
95 return thenbpar;
96}
97
98Standard_Integer Interface_ParamSet::Append (const Interface_FileParameter& FP)
99{
100 // Ici, FP tout pret : pas de gestion memoire sur String (dommage)
101
102 thenbpar ++;
103 if (thenbpar > themxpar) {
104 thenext = new Interface_ParamSet (themxpar,1);
105 return thenbpar + thenext->Append(FP);
106 }
107 thelist->SetValue(thenbpar,FP);
108 return thenbpar;
109}
110
111Standard_Integer Interface_ParamSet::NbParams () const
112{ return thenbpar; }
113
114const Interface_FileParameter& Interface_ParamSet::Param (const Standard_Integer num) const
115{
116 if (num > themxpar) return thenext->Param(num - themxpar);
117 else return thelist->Value(num);
118}
119
120Interface_FileParameter& Interface_ParamSet::ChangeParam (const Standard_Integer num)
121{
122 if (num > themxpar) return thenext->ChangeParam(num - themxpar);
123 else return thelist->ChangeValue(num);
124}
125
126void Interface_ParamSet::SetParam (const Standard_Integer num, const Interface_FileParameter& FP)
127{
128 if (num > themxpar) thenext->SetParam(num - themxpar, FP);
129 else thelist->SetValue(num,FP);
130}
131
132Handle(Interface_ParamList) Interface_ParamSet::Params (const Standard_Integer num,
133 const Standard_Integer nb) const
134{
135 Standard_Integer i, n0 = num-1, nbp = nb;
136 if (num > themxpar)
137 return thenext->Params (num-themxpar,nb);
138 if (num == 0 && nb == 0) {
139 n0 = 0; nbp = thenbpar;
140 if (thenbpar <= themxpar)
141 return thelist; // et zou
142 }
143 Handle(Interface_ParamList) list = new Interface_ParamList;
144 if (nb == 0)
145 return list;
146
147 for (i = 1; i <= nbp; i ++) list->SetValue(i,Param(n0+i));
148 return list;
149}
150
151void Interface_ParamSet::Destroy ()
152{
153 // if (!thenext.IsNull()) thenext->Destroy();
154 thenext.Nullify();
155 // Destruction "manuelle" (gestion memoire directe)
156 if (theval) delete [] theval;
157 theval = NULL;
158 thelist->Clear();
159 thelist.Nullify();
160}