c050c2abf7e4dc85bc4e1ba6413ff6b75603cca3
[occt.git] / src / IGESSelect / IGESSelect_SetLabel.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
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.
7 //
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.
10 //
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.
17
18 #include <IGESSelect_SetLabel.ixx>
19 #include <Interface_Macros.hxx>
20 #include <IGESData_IGESEntity.hxx>
21 #include <TCollection_HAsciiString.hxx>
22
23 IGESSelect_SetLabel::IGESSelect_SetLabel
24   (const Standard_Integer mode, const Standard_Boolean enforce)
25     : IGESSelect_ModelModifier (Standard_False) ,
26       themode (mode) , theforce (enforce)    {  }
27
28     void  IGESSelect_SetLabel::Performing
29   (IFSelect_ContextModif& ctx,
30    const Handle(IGESData_IGESModel)& target,
31    Interface_CopyTool& TC) const
32 {
33   Handle(TCollection_HAsciiString) lab;
34   for (ctx.Start(); ctx.More(); ctx.Next()) {
35     DeclareAndCast(IGESData_IGESEntity,iges,ctx.ValueResult());
36     if (iges.IsNull()) continue;
37     if (themode == 0)  {  iges->SetLabel(lab); continue;  }
38
39 // mode = 1 : mettre DEnnn , nnn est le DE Number
40     lab = iges->ShortLabel();
41     if (theforce) lab.Nullify();
42     if (!lab.IsNull()) {
43       if (lab->Length() > 2) {
44         if (lab->Value(1) == 'D' && lab->Value(2) == 'E' &&
45             atoi( &(lab->ToCString())[2] ) > 0)
46           lab.Nullify();
47       }
48     }
49 //    Si lab nul : le recalculer
50     if (lab.IsNull()) {
51       lab = new TCollection_HAsciiString(target->Number(iges)*2-1);
52       lab->Insert (1,"DE");
53     }
54     iges->SetLabel(lab);
55   }
56 }
57
58     TCollection_AsciiString  IGESSelect_SetLabel::Label () const
59 {
60   TCollection_AsciiString lab;
61   if (themode == 0) lab.AssignCat ("Clear Short Label");
62   if (themode == 1) lab.AssignCat ("Set Short Label to DE Number");
63   if (theforce) lab.AssignCat (" (enforced)");
64   return lab;
65 }