1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <Interface_Category.ixx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TColStd_SequenceOfAsciiString.hxx>
21 #include <Interface_GeneralModule.hxx>
24 static Standard_CString unspec = "unspecified";
26 static TColStd_SequenceOfAsciiString& thecats()
28 static TColStd_SequenceOfAsciiString thecat;
35 Interface_Category::Interface_Category ()
36 : thegtool (new Interface_GTool) { Init(); }
38 Interface_Category::Interface_Category
39 (const Handle(Interface_Protocol)& protocol)
40 : thegtool (new Interface_GTool(protocol)) { Init(); }
42 Interface_Category::Interface_Category
43 (const Handle(Interface_GTool)& gtool)
44 : thegtool (gtool) { Init(); }
46 void Interface_Category::SetProtocol
47 (const Handle(Interface_Protocol)& protocol)
48 { thegtool->SetProtocol(protocol); }
50 Standard_Integer Interface_Category::CatNum
51 (const Handle(Standard_Transient)& ent, const Interface_ShareTool& shares)
53 if (ent.IsNull()) return 0;
55 Handle(Interface_GeneralModule) module;
56 if (!thegtool->Select (ent,module,CN)) return 0;
57 return module->CategoryNumber (CN,ent,shares);
60 void Interface_Category::ClearNums ()
63 void Interface_Category::Compute
64 (const Handle(Interface_InterfaceModel)& model,
65 const Interface_ShareTool& shares)
68 if (model.IsNull()) return;
69 Standard_Integer CN, i, nb = model->NbEntities();
70 thegtool->Reservate (nb);
72 thenum = new TColStd_HArray1OfInteger (1,nb); thenum->Init(0);
73 for (i = 1; i <= nb; i ++) {
74 Handle(Standard_Transient) ent = model->Value(i);
75 if (ent.IsNull()) continue;
76 Handle(Interface_GeneralModule) module;
77 if (!thegtool->Select (ent,module,CN)) continue;
78 thenum->SetValue (i,module->CategoryNumber (CN,ent,shares));
82 Standard_Integer Interface_Category::Num (const Standard_Integer nument) const
84 if (thenum.IsNull()) return 0;
85 if (nument < 1 || nument > thenum->Length()) return 0;
86 return thenum->Value(nument);
90 // ########## LISTE DES CATEGORIES ##########
92 Standard_Integer Interface_Category::AddCategory (const Standard_CString name)
94 Standard_Integer num = Interface_Category::Number (name);
95 if (num > 0) return num;
96 thecats().Append (TCollection_AsciiString(name));
97 return thecats().Length()+1;
100 Standard_Integer Interface_Category::NbCategories ()
101 { return thecats().Length(); }
103 Standard_CString Interface_Category::Name (const Standard_Integer num)
105 if (num < 0) return "";
106 if (num < 1 || num > thecats().Length()) return unspec;
107 return thecats().Value(num).ToCString();
111 Standard_Integer Interface_Category::Number (const Standard_CString name)
113 Standard_Integer i, nb = thecats().Length();
114 for (i = 1; i <= nb; i ++) {
115 if (thecats().Value(i).IsEqual(name)) return i;
121 void Interface_Category::Init ()
123 if (init) return; init = 1;
124 init = Interface_Category::AddCategory ("Shape");
125 init = Interface_Category::AddCategory ("Drawing");
126 init = Interface_Category::AddCategory ("Structure");
127 init = Interface_Category::AddCategory ("Description");
128 init = Interface_Category::AddCategory ("Auxiliary");
129 init = Interface_Category::AddCategory ("Professional");
130 init = Interface_Category::AddCategory ("FEA");
131 init = Interface_Category::AddCategory ("Kinematics");
132 init = Interface_Category::AddCategory ("Piping");