Commit b0845329 authored by snuverink_j's avatar snuverink_j

remove Editor command: EDIT

parent a8ba54ae
......@@ -75,7 +75,6 @@ add_subdirectory (Attributes)
add_subdirectory (BasicActions)
add_subdirectory (Classic)
add_subdirectory (Distribution)
add_subdirectory (Editor)
add_subdirectory (Elements)
add_subdirectory (Expressions)
add_subdirectory (Lines)
......
set (_SRCS
Edit.cpp
EditCmd.cpp
EditCycle.cpp
EditEnd.cpp
EditFlatten.cpp
EditInstall.cpp
EditMove.cpp
EditParser.cpp
EditReflect.cpp
EditRemove.cpp
EditReplace.cpp
EditSelect.cpp
)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}
)
add_opal_sources(${_SRCS})
set (HDRS
EditCmd.h
EditCycle.h
EditEnd.h
EditFlatten.h
Edit.h
EditInstall.h
EditMove.h
EditParser.h
EditReflect.h
EditRemove.h
EditReplace.h
EditSelect.h
)
install (FILES ${HDRS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/Editor")
# vi: set et ts=4 sw=4 sts=4:
# Local Variables:
# mode: cmake
# cmake-tab-width: 4
# indent-tabs-mode: nil
# require-final-newline: nil
# End:
This diff is collapsed.
#ifndef OPAL_Edit_HH
#define OPAL_Edit_HH
// ------------------------------------------------------------------------
// $RCSfile: Edit.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: Edit
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Editor/EditParser.h"
#include "MemoryManagement/Pointer.h"
#include "Lines/Sequence.h"
#include <string>
class Attribute;
class EditParser;
class ElementBase;
class PlaceRep;
class RangeRep;
// Class Edit
// ------------------------------------------------------------------------
/// This class contains all data for the sequence editor.
// It acts as a communication area between the sequence editor commands.
class Edit {
public:
/// Constructor.
// Prepares the given sequence for editing.
// Makes a copy with all drifts removed.
Edit(Sequence *);
~Edit();
/// The type of line contained in a sequence.
typedef Sequence::TLine TLine;
/// The line iterator for a sequence.
typedef Sequence::TLine::iterator iterator;
/// Cycle the edit sequence.
// The new start point is at [b]start[/b].
bool cycle(const PlaceRep &start);
/// Finish editing.
// Reconstruct the modified sequence as required.
// If a new name is given, make a copy, otherwise if the sequence is
// modified, overwrite the original.
void finish(const std::string &newName);
/// Flatten the edit sequence.
void flatten();
/// Install multiple elements.
// New element [b]elem[/b] at position [b]at[/b] from all selected
// elements.
int installMultiple(ElementBase *, double);
/// Install element relative to place.
// New element [b]elem[/b] at position [b]at[/b] from [b]from[/b]
// (if given) or from origin.
int installSingle(const PlaceRep &, ElementBase *, double);
/// Move multiple elements.
// Move all selected elements by [b]by[/b].
int moveMultiple(double by);
/// Move single element.
// Move element at [b]pos[/b] to absolute position.
int moveSingleAbs(const PlaceRep &, double to);
/// Move single element.
// Move element at [b]pos[/b] by given amount.
int moveSingleRel(const PlaceRep &, const PlaceRep &, double to);
/// Reflect the edit sequence.
void reflect();
/// Remove multiple elements.
// Remove all selected elements.
int removeMultiple();
/// Remove single element.
// Remove element at [b]pos[/b]
int removeSingle(const PlaceRep &);
/// Replace multiple elements.
// Replace all selected elements by [b]elem[/b].
int replaceMultiple(ElementBase *elem);
/// Replace single element.
// Replace element at [b]pos[/b] by [b]elem[/b].
int replaceSingle(const PlaceRep &, ElementBase *elem);
/// Select elements in the edit sequence.
// Use range, class and regular expression.
int select(const RangeRep &rng, const std::string &cls,
const std::string &typ, const std::string &patt);
/// Clear all selection flags.
void selectClear();
/// Set all selection flags.
void selectFull();
/// The original sequence.
Pointer<Sequence> itsSequence;
/// The edit sequence.
Pointer<TLine> itsLine;
/// Modify flag.
// If true, the edit sequence is different from the original.
bool isModified;
/// The parser used during a sequence edit.
EditParser parser;
/// Pointer to the edit data.
static Edit *block;
private:
// Not implemented.
Edit();
Edit(const Edit &);
void operator=(const Edit &);
// Add an element to the install list.
void install(TLine &, ElementBase *, double);
// Install multiple elements.
int installMultiple(bool, TLine &, ElementBase *, double);
// Install single element.
int installSingle(bool, TLine &, PlaceRep &, ElementBase *, double);
// Move one element.
void merge(TLine &, TLine &);
// Move multiple elements.
int moveMultiple(bool, TLine &, double by);
// Move single element.
int moveSingleAbs(bool, TLine &, PlaceRep &, double to);
int moveSingleRel(bool, TLine &, PlaceRep &, PlaceRep &, double to);
// Reflect the edit sequence.
TLine *reflect(TLine &);
// Remove multiple elements.
int removeMultiple(bool, TLine &);
// Remove single element.
int removeSingle(bool, TLine &, PlaceRep &);
// Replace multiple elements.
int replaceMultiple(bool, TLine &, ElementBase *elem);
// Replace single element.
int replaceSingle(bool, TLine &, PlaceRep &, ElementBase *elem);
// Warning message.
void invalidLine(const char msg[]);
void invalidShare(const char msg[]);
};
#endif // OPAL_Edit_HH
// ------------------------------------------------------------------------
// $RCSfile: EditCmd.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: EditCmd
// The class for the OPAL sequence editor SEQEDIT command.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Editor/EditCmd.h"
#include "AbstractObjects/OpalData.h"
#include "Attributes/Attributes.h"
#include "Editor/Edit.h"
#include "Utilities/OpalException.h"
// Class EditCmd
// ------------------------------------------------------------------------
EditCmd::EditCmd():
Action(1, "SEQEDIT",
"The \"SEQEDIT\" command specifies a sequence for editing.") {
itsAttr[0] = Attributes::makeString
("SEQUENCE", "Name of sequence to be edited");
registerOwnership(AttributeHandler::COMMAND);
AttributeHandler::addAttributeOwner("SEQEDIT", AttributeHandler::COMMAND, "REPLACE");
AttributeHandler::addAttributeOwner("SEQEDIT", AttributeHandler::COMMAND, "SELECT");
AttributeHandler::addAttributeOwner("SEQEDIT", AttributeHandler::COMMAND, "ENDEDIT");
AttributeHandler::addAttributeOwner("SEQEDIT", AttributeHandler::COMMAND, "MOVE");
AttributeHandler::addAttributeOwner("SEQEDIT", AttributeHandler::COMMAND, "INSTALL");
AttributeHandler::addAttributeOwner("SEQEDIT", AttributeHandler::COMMAND, "FLATTEN");
AttributeHandler::addAttributeOwner("SEQEDIT", AttributeHandler::COMMAND, "CYCLE");
AttributeHandler::addAttributeOwner("SEQEDIT", AttributeHandler::COMMAND, "REMOVE");
}
EditCmd::EditCmd(const std::string &name, EditCmd *parent):
Action(name, parent)
{}
EditCmd::~EditCmd()
{}
EditCmd *EditCmd::clone(const std::string &name) {
return new EditCmd(name, this);
}
void EditCmd::execute() {
// The parser strategy for sequence edit mode.
std::string seqName = Attributes::getString(itsAttr[0]);
if(seqName == "") {
throw OpalException("EditCmd::execute()",
"Sequence name is required for \"SEQEDIT\".");
} else {
// find sequence definition
Object *object = OpalData::getInstance()->find(seqName);
Sequence *seq = dynamic_cast<Sequence *>(object);
if(seq == 0) {
throw OpalException("EditCmd::execute()",
"Sequence \"" + seqName + "\" not found.");
} else {
// Execute edit block.
Edit::block = new Edit(seq);
Edit::block->parser.run();
// Clean up.
delete Edit::block;
Edit::block = 0;
}
}
}
\ No newline at end of file
#ifndef OPAL_EditCmd_HH
#define OPAL_EditCmd_HH
// ------------------------------------------------------------------------
// $RCSfile: EditCmd.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: EditCmd
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "AbstractObjects/Action.h"
// Class EditCmd
// ------------------------------------------------------------------------
/// The sequence editor SEQEDIT command.
class EditCmd: public Action {
public:
/// Exemplar constructor.
EditCmd();
virtual ~EditCmd();
/// Make clone.
virtual EditCmd *clone(const std::string &name);
/// Execute the command.
virtual void execute();
private:
// Not implemented.
EditCmd(const EditCmd &);
void operator=(const EditCmd &);
// Clone constructor.
EditCmd(const std::string &name, EditCmd *parent);
};
#endif // OPAL_EditCmd_HH
// ------------------------------------------------------------------------
// $RCSfile: EditCycle.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: EditCycle
// The class for the OPAL sequence editor CYCLE command.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Editor/EditCycle.h"
#include "AbstractObjects/PlaceRep.h"
#include "Attributes/Attributes.h"
#include "Editor/Edit.h"
#include "Utilities/OpalException.h"
#include "Utilities/Options.h"
#include <iostream>
// Class EditCycle
// ------------------------------------------------------------------------
EditCycle::EditCycle():
Editor(1, "CYCLE",
"The \"CYCLE\" sub-command changes the starting point "
"by cyclic interchange.") {
itsAttr[0] = Attributes::makePlace
("START", "The new start position for the sequence");
registerOwnership(AttributeHandler::SUB_COMMAND);
}
EditCycle::EditCycle(const std::string &name, EditCycle *parent):
Editor(name, parent)
{}
EditCycle::~EditCycle()
{}
EditCycle *EditCycle::clone(const std::string &name) {
return new EditCycle(name, this);
}
void EditCycle::execute() {
const PlaceRep start = Attributes::getPlace(itsAttr[0]);
if(Edit::block->cycle(start)) {
if(Options::info) {
std::cerr << "\nStart position changed to \"" << itsAttr[0] << "\".\n"
<< std::endl;
}
} else {
throw OpalException("EditCycle::execute()", "Could not find place \"" +
itsAttr[0].getImage() + "\" in top-level sequence.");
}
}
\ No newline at end of file
#ifndef OPAL_EditCycle_HH
#define OPAL_EditCycle_HH
// ------------------------------------------------------------------------
// $RCSfile: EditCycle.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: EditCycle
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "AbstractObjects/Editor.h"
// Class EditCycle
// ------------------------------------------------------------------------
/// The sequence editor CYCLE command.
class EditCycle: public Editor {
public:
/// Exemplar constructor.
EditCycle();
virtual ~EditCycle();
/// Make clone.
virtual EditCycle *clone(const std::string &name);
/// Execute the command.
virtual void execute();
private:
// Not implemented.
EditCycle(const EditCycle &);
void operator=(const EditCycle &);
// Clone constructor.
EditCycle(const std::string &name, EditCycle *parent);
};
#endif // OPAL_EditCycle_HH
// ------------------------------------------------------------------------
// $RCSfile: EditEnd.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: EditEnd
// The class for the OPAL sequence editor ENDEDIT command.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Editor/EditEnd.h"
#include "Attributes/Attributes.h"
#include "Editor/Edit.h"
// Class EditEnd
// ------------------------------------------------------------------------
EditEnd::EditEnd():
Editor(1, "ENDEDIT",
"The \"ENDEDIT\" sub-command terminates sequence editing mode.") {
itsAttr[0] = Attributes::makeString
("NAME", "New name for the edited sequence (default = old name)");
registerOwnership(AttributeHandler::SUB_COMMAND);
}
EditEnd::EditEnd(const std::string &name, EditEnd *parent):
Editor(name, parent)
{}
EditEnd::~EditEnd()
{}
EditEnd *EditEnd::clone(const std::string &name) {
return new EditEnd(name, this);
}
void EditEnd::execute() {
try {
std::string newName = Edit::block->itsSequence->getOpalName();
if(itsAttr[0]) newName = Attributes::getString(itsAttr[0]);
Edit::block->finish(newName);
Edit::block->parser.stop();
} catch(...) {
Edit::block->parser.stop();
throw;
}
}
\ No newline at end of file
#ifndef OPAL_EditEnd_HH
#define OPAL_EditEnd_HH
// ------------------------------------------------------------------------
// $RCSfile: EditEnd.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: EditEnd
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "AbstractObjects/Editor.h"
// Class EditEnd
// ------------------------------------------------------------------------
/// The sequence editor ENDEDIT command.
class EditEnd: public Editor {
public:
/// Exemplar constructor.
EditEnd();
virtual ~EditEnd();
/// Make clone.
virtual EditEnd *clone(const std::string &name);
/// Execute the command.
virtual void execute();
private:
// Not implemented.
EditEnd(const EditEnd &);
void operator=(const EditEnd &);
// Clone constructor.
EditEnd(const std::string &name, EditEnd *parent);
};
#endif // OPAL_EditEnd_HH
// ------------------------------------------------------------------------
// $RCSfile: EditFlatten.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: EditFlatten
// The class for the OPAL sequence editor FLATTEN command.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Editor/EditFlatten.h"
#include "Editor/Edit.h"
#include "Lines/Sequence.h"
#include "Utilities/Options.h"
#include <iostream>
// Class EditFlatten
// ------------------------------------------------------------------------
EditFlatten::EditFlatten():
Editor(0, "FLATTEN",
"The \"FLATTEN\" sub-command creates a flat sequence from the "
"sequence being edited.")
{}
EditFlatten::EditFlatten(const std::string &name, EditFlatten *parent):
Editor(name, parent)
{}
EditFlatten::~EditFlatten()
{}
EditFlatten *EditFlatten::clone(const std::string &name) {
return new EditFlatten(name, this);
}
void EditFlatten::execute() {
Edit::block->flatten();
if(Options::info) {
std::cerr << "\nSequence has been flattened.\n" << std::endl;
}
}
#ifndef OPAL_EditFlatten_HH
#define OPAL_EditFlatten_HH
// ------------------------------------------------------------------------
// $RCSfile: EditFlatten.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: EditFlatten
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:38 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "AbstractObjects/Editor.h"