0024023: Revamp the OCCT Handle -- general
[occt.git] / src / IGESSelect / IGESSelect_AddGroup.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <IGESSelect_AddGroup.ixx>
15 #include <Interface_Check.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <IGESBasic_Group.hxx>
18 #include <IGESData_HArray1OfIGESEntity.hxx>
19 #include <IGESData_IGESEntity.hxx>
20 #include <Interface_Macros.hxx>
21
22
23
24 IGESSelect_AddGroup::IGESSelect_AddGroup ()
25     : IGESSelect_ModelModifier (Standard_True)    {  }
26
27 void  IGESSelect_AddGroup::Performing (IFSelect_ContextModif& ctx,
28                                        const Handle(IGESData_IGESModel)& target,
29                                        Interface_CopyTool& /*TC*/) const
30 {
31   if (ctx.IsForAll()) {
32     ctx.CCheck(0)->AddFail ("Add Group : Selection required not defined");
33     return;
34   }
35   Interface_EntityIterator list = ctx.SelectedResult();
36   Standard_Integer i = 0 , nb = list.NbEntities();
37   if (nb == 0) {
38     ctx.CCheck(0)->AddWarning ("Add Group : No entity selected");
39     return;
40   }
41   if (nb == 1) {
42     ctx.CCheck(0)->AddWarning ("Add Group : ONE entity selected");
43     return;
44   }
45   Handle(IGESData_HArray1OfIGESEntity) arr =
46     new IGESData_HArray1OfIGESEntity(1,nb);
47   for (ctx.Start(); ctx.More(); ctx.Next()) {
48     DeclareAndCast(IGESData_IGESEntity,ent,ctx.ValueResult());
49     i ++;
50     arr->SetValue(i,ent);
51   }
52   Handle(IGESBasic_Group) gr = new IGESBasic_Group;
53   gr->Init (arr);
54   target->AddEntity(gr);
55 }
56
57
58     TCollection_AsciiString  IGESSelect_AddGroup::Label () const
59       {  return TCollection_AsciiString ("Add Group");  }