OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
EditMove.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: EditMove.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: EditMove
10 // The class for the OPAL sequence editor MOVE command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:38 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Editor/EditMove.h"
21 #include "Attributes/Attributes.h"
22 #include "Editor/Edit.h"
23 #include "Utilities/Options.h"
24 #include <iostream>
25 
26 
27 // Class EditMove
28 // ------------------------------------------------------------------------
29 
30 // The attributes of class EditMove.
31 
32 namespace {
33  enum {
34  SELECTED, // If true, move selected elements.
35  ELEMENT, // The element to be moved.
36  BY, // The shift amount.
37  TO, // The new position.
38  FROM, // An origin name.
39  SIZE
40  };
41 }
42 
43 
45  Editor(SIZE, "MOVE",
46  "The \"MOVE\" sub-command moves element(s) in the sequence "
47  "being edited.") {
48  itsAttr[SELECTED] = Attributes::makeBool
49  ("SELECTED", "If true, all selected elements are moved");
51  ("ELEMENT", "Name of single element to be moved");
53  ("BY", "Amount in m by which elements should be moved");
55  ("TO", "New position in m relative to origin");
57  ("FROM", "Name of element defining the origin (default is start)");
58 
60 }
61 
62 
63 EditMove::EditMove(const std::string &name, EditMove *parent):
64  Editor(name, parent)
65 {}
66 
67 
69 {}
70 
71 
72 EditMove *EditMove::clone(const std::string &name) {
73  return new EditMove(name, this);
74 }
75 
76 
78  const PlaceRep cls = Attributes::getPlace(itsAttr[ELEMENT]);
79  int count = 0;
80 
81  if(Attributes::getBool(itsAttr[SELECTED])) {
82  double by = Attributes::getReal(itsAttr[BY]);
83  count = Edit::block->moveMultiple(by);
84  } else if(itsAttr[BY]) {
85  double by = Attributes::getReal(itsAttr[BY]);
86  count = Edit::block->moveSingleRel(cls, cls, by);
87  } else if(itsAttr[FROM]) {
88  const PlaceRep from = Attributes::getPlace(itsAttr[FROM]);
89  double to = Attributes::getReal(itsAttr[TO]);
90  count = Edit::block->moveSingleRel(cls, from, to);
91  } else {
92  double to = Attributes::getReal(itsAttr[TO]);
93  count = Edit::block->moveSingleAbs(cls, to);
94  }
95 
96  if(Options::info) {
97  if(count == 0) {
98  std::cerr << "\nNo element";
99  } else if(count == 1) {
100  std::cerr << "\n1 element";
101  } else {
102  std::cerr << '\n' << count << " elements";
103  }
104 
105  std::cerr << " moved.\n" << std::endl;
106  }
107 }
virtual ~EditMove()
Definition: EditMove.cpp:68
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
bool info
Info flag.
Definition: Options.cpp:8
The base class for all OPAL sequence editor commands.
Definition: Editor.h:31
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
virtual EditMove * clone(const std::string &name)
Make clone.
Definition: EditMove.cpp:72
PlaceRep getPlace(const Attribute &attr)
Get place value.
Definition: Attributes.cpp:143
Representation of a place within a beam line or sequence.
Definition: PlaceRep.h:41
int moveSingleAbs(const PlaceRep &, double to)
Move single element.
Definition: Edit.cpp:275
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
The sequence editor MOVE command.
Definition: EditMove.h:28
static Edit * block
Pointer to the edit data.
Definition: Edit.h:134
Attribute makePlace(const std::string &name, const std::string &help)
Create a place attribute.
Definition: Attributes.cpp:137
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
EditMove()
Exemplar constructor.
Definition: EditMove.cpp:44
int moveSingleRel(const PlaceRep &, const PlaceRep &, double to)
Move single element.
Definition: Edit.cpp:281
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
int moveMultiple(double by)
Move multiple elements.
Definition: Edit.cpp:270
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
virtual void execute()
Execute the command.
Definition: EditMove.cpp:77