editableScene.h

Go to the documentation of this file.
00001 /*    THIS IS EXPERIMENTAL CODE  
00002  *
00003  *    WE GIVE NO WARRANTY
00004  *    
00005  *    USE AT YOUR OWN RISK!!!!!!
00006  */
00007 
00008 #ifndef BALL_VIEW_WIDGETS_EDITABLESCENE_H
00009 #define BALL_VIEW_WIDGETS_EDITABLESCENE_H
00010 
00011 
00012 #ifndef BALL_KERNEL_SYSTME_H
00013 #include <BALL/KERNEL/system.h>
00014 #endif
00015 
00016 #ifndef BALL_VIEW_WIDGETS_SCENE_H
00017 #include <BALL/VIEW/WIDGETS/scene.h>
00018 #endif
00019 
00020 #ifndef BALL_KERNEL_MOLECULE_H
00021 #include <BALL/KERNEL/molecule.h>
00022 #endif
00023 
00024 #ifndef BALL_VIEW_KERNEL_COMMON_H
00025 # include <BALL/VIEW/KERNEL/common.h>
00026 #endif 
00027 
00028 #ifndef BALL_MATHS_VECTOR2_H
00029 # include <BALL/MATHS/vector2.h>
00030 #endif
00031 
00032 #ifndef BALL_STRUCTURE_FRAGMENTDB_H
00033 # include <BALL/STRUCTURE/fragmentDB.h>
00034 #endif
00035 
00036 #include <QtGui/qcursor.h>
00037 
00038 namespace BALL
00039 {
00040   namespace VIEW
00041   {
00042 
00043 class EditSettings;
00044 
00049 class BALL_VIEW_EXPORT EditableScene
00050   : public Scene
00051 {
00052   Q_OBJECT //macro for QT-Messages
00053 
00054   public:
00055 
00056   BALL_EMBEDDABLE(EditableScene, ModularWidget) 
00057 
00058   // This class represents a single edit operation and stores its type and
00059   // parameters. This can be used to implement undo functionality.
00060   class BALL_VIEW_EXPORT EditOperation
00061   {
00062     public:
00063 
00065     EditOperation();
00066 
00068     EditOperation(Atom* atom, Bond* bond, String description= "Added Object", int operation=0);
00069 
00071     EditOperation(const EditOperation& eOperation);
00072 
00074     virtual ~EditOperation();
00075 
00077     enum OperationType
00078     {
00079       DEFAULT,
00080       ADDED__ATOM,
00081       ADDED__BOND,
00082       CHANGED__TYPE
00083         // DELETED__ATOM
00084         // DELETED__BOND
00085         //CHANGED__SYSTEM
00086         //MOVED__ATOM
00087     };
00088 
00089     int operationType;
00090     Atom* atom;
00091     Bond* bond;
00092     String description;
00093   };
00094 
00096   enum EditMode
00097   {
00098     // 
00099     EDIT__MODE = PICKING__MODE + 1
00100   };
00101 
00103   EditableScene();
00104 
00106   EditableScene(QWidget* parent_widget, const char* name = NULL, Qt::WFlags w_flags = 0);
00107 
00109   EditableScene (const EditableScene& eScene, QWidget* parent_widget = NULL, const char* name = NULL, Qt::WFlags wflags = 0);
00110 
00112   virtual ~EditableScene();
00113 
00115   void initializeWidget(MainControl& main_control);
00116 
00118   void checkMenu(MainControl& main_control);
00119 
00121   void initializePreferencesTab(Preferences &preferences);
00122   
00124   void finalizePreferencesTab(Preferences &preferences);
00125 
00127   virtual void applyPreferences();
00128   
00130   void showContextMenu(QPoint pos);
00131 
00133   virtual void setMode(ModeType mode);
00134 
00135   void addStructure(String name);
00136 
00138   void setCursor(String c);
00139 
00141   void setElementCursor();
00142 
00144   public slots:
00145 
00146   virtual void mousePressEvent(QMouseEvent* e);
00147   virtual void mouseMoveEvent(QMouseEvent *e);
00148   virtual void mouseReleaseEvent(QMouseEvent *e);
00149   virtual void wheelEvent(QWheelEvent* qmouse_event);
00150   void createNewMolecule();
00151   void saturateWithHydrogens();
00152   void optimizeStructure();
00153   void computeBondOrders();
00154 
00155   // slots for communication with PTEDialog
00156   void setEditElementType(int element_number);
00157   int getEditElementType();
00158               
00160   protected slots:
00161 
00162   virtual void editMode_();
00163   void deleteAtom_();
00164   void changeElement_();
00165   void deleteBond_();
00166   void changeBondOrder_();
00167   void activatedOrderItem_(QAction* action);
00168   void moveAtom_();
00169   void atomProperties_();
00170   void createMolecule_();
00171   void addStructure_();
00172   void setFormalCharge_();
00173 
00175   signals:
00176 
00177   // signal for communication with EditOperationDialog
00178   void newEditOperation(EditableScene::EditOperation &eo);
00179 
00181   protected:
00182 
00183   virtual void addToolBarEntries(QToolBar* tb);
00184 
00186   virtual void keyPressEvent(QKeyEvent* e);
00187   virtual void mouseDoubleClickEvent(QMouseEvent* e);
00188   virtual bool reactToKeyEvent_(QKeyEvent* e);
00189 
00190   virtual void onNotify(Message *message);
00191 
00197   void insert_(int x_, int y_, PDBAtom &atom_);
00198 
00199   void merge_(Composite* a1, Composite* a2);
00200 
00205   TVector2<float> getScreenPosition_(Vector3 vec);
00206 
00207   void getClickedItems_(int x, int y);
00208 
00209   void init_();
00210 
00211   String getBondOrderString_(Index order);
00212 
00213   List<AtomContainer*> getContainers_();
00214 
00215   void changeBondOrder_(Index delta);
00216   void deselect_(bool update=true);
00217   void renderGrid_();
00218 
00219   QAction* edit_id_, *new_molecule_action_, *optimize_action_, *add_hydrogens_action_, *element_action_;  
00220   QAction* bondorders_action_;
00221   
00222   Atom* current_atom_;
00223   Bond* current_bond_;
00224 
00225   Vector3 atom_pos_;
00226 
00227   // pick atoms/bonds only in highlighted AtomContainer?
00228   static bool only_highlighted_;
00229   // element for new atoms
00230   int atomic_number_;
00231   // name for newly created atoms
00232   Position atom_number_;
00233   // order for new bonds
00234   int bond_order_;
00235   Position last_y_;
00236   Qt::MouseButtons last_buttons_;
00237 
00238   //undo stack
00239   vector<EditOperation> undo_;
00240   EditSettings* edit_settings_;
00241   QPoint   menu_point_;
00242   FragmentDB fragment_db_;
00243   bool fragment_db_initialized_;
00244   bool temp_move_;
00245   QToolBar* toolbar_edit_controls_;
00246   QList<QAction*> toolbar_actions_edit_controls_;
00247 };
00248 
00249   }//end of namespace
00250 } // end of namespace
00251 #endif