1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Interface_Category.hxx>
16 #include <Interface_GeneralModule.hxx>
17 #include <Interface_GTool.hxx>
18 #include <Interface_InterfaceModel.hxx>
19 #include <Interface_Protocol.hxx>
20 #include <Interface_ShareTool.hxx>
21 #include <Standard_Transient.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TColStd_SequenceOfAsciiString.hxx>
26 static Standard_CString unspec = "unspecified";
28 static TColStd_SequenceOfAsciiString& thecats()
30 static TColStd_SequenceOfAsciiString thecat;
37 Interface_Category::Interface_Category ()
38 : thegtool (new Interface_GTool) { Init(); }
40 Interface_Category::Interface_Category
41 (const Handle(Interface_Protocol)& protocol)
42 : thegtool (new Interface_GTool(protocol)) { Init(); }
44 Interface_Category::Interface_Category
45 (const Handle(Interface_GTool)& gtool)
46 : thegtool (gtool) { Init(); }
48 void Interface_Category::SetProtocol
49 (const Handle(Interface_Protocol)& protocol)
50 { thegtool->SetProtocol(protocol); }
52 Standard_Integer Interface_Category::CatNum
53 (const Handle(Standard_Transient)& ent, const Interface_ShareTool& shares)
55 if (ent.IsNull()) return 0;
57 Handle(Interface_GeneralModule) module;
58 if (!thegtool->Select (ent,module,CN)) return 0;
59 return module->CategoryNumber (CN,ent,shares);
62 void Interface_Category::ClearNums ()
65 void Interface_Category::Compute
66 (const Handle(Interface_InterfaceModel)& model,
67 const Interface_ShareTool& shares)
70 if (model.IsNull()) return;
71 Standard_Integer CN, i, nb = model->NbEntities();
72 thegtool->Reservate (nb);
74 thenum = new TColStd_HArray1OfInteger (1,nb); thenum->Init(0);
75 for (i = 1; i <= nb; i ++) {
76 Handle(Standard_Transient) ent = model->Value(i);
77 if (ent.IsNull()) continue;
78 Handle(Interface_GeneralModule) module;
79 if (!thegtool->Select (ent,module,CN)) continue;
80 thenum->SetValue (i,module->CategoryNumber (CN,ent,shares));
84 Standard_Integer Interface_Category::Num (const Standard_Integer nument) const
86 if (thenum.IsNull()) return 0;
87 if (nument < 1 || nument > thenum->Length()) return 0;
88 return thenum->Value(nument);
92 // ########## LISTE DES CATEGORIES ##########
94 Standard_Integer Interface_Category::AddCategory (const Standard_CString name)
96 Standard_Integer num = Interface_Category::Number (name);
97 if (num > 0) return num;
98 thecats().Append (TCollection_AsciiString(name));
99 return thecats().Length()+1;
102 Standard_Integer Interface_Category::NbCategories ()
103 { return thecats().Length(); }
105 Standard_CString Interface_Category::Name (const Standard_Integer num)
107 if (num < 0) return "";
108 if (num < 1 || num > thecats().Length()) return unspec;
109 return thecats().Value(num).ToCString();
113 Standard_Integer Interface_Category::Number (const Standard_CString name)
115 Standard_Integer i, nb = thecats().Length();
116 for (i = 1; i <= nb; i ++) {
117 if (thecats().Value(i).IsEqual(name)) return i;
123 void Interface_Category::Init ()
125 if (init) return; init = 1;
126 init = Interface_Category::AddCategory ("Shape");
127 init = Interface_Category::AddCategory ("Drawing");
128 init = Interface_Category::AddCategory ("Structure");
129 init = Interface_Category::AddCategory ("Description");
130 init = Interface_Category::AddCategory ("Auxiliary");
131 init = Interface_Category::AddCategory ("Professional");
132 init = Interface_Category::AddCategory ("FEA");
133 init = Interface_Category::AddCategory ("Kinematics");
134 init = Interface_Category::AddCategory ("Piping");