File indexing completed on 2024-04-28 16:08:33

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2014 by Linuxstopmotion contributors;              *
0003  *   see the AUTHORS file for details.                                     *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef DOMAINFACADE_H
0021 #define DOMAINFACADE_H
0022 
0023 #include <vector>
0024 
0025 class Animation;
0026 class Observer;
0027 class Frontend;
0028 class VideoEncoder;
0029 class StringIterator;
0030 class UndoRedoObserver;
0031 struct GrabberDevice;
0032 
0033 /**
0034  * Singleton facade for the domain level. All requests into the domain layer
0035  * has to pass through this facade. The only exception is observer requests
0036  * for display data.
0037  *
0038  * DomainFacade is implemented with lazy allocation.
0039  *
0040  *@author Bjoern Erik Nilsen & Fredrik Berg Kjoelstad
0041  */
0042 class DomainFacade {
0043 public:
0044     ~DomainFacade();
0045 
0046     /**
0047      * Static function to retrieve the factory instance object from the singleton
0048      * class.
0049      * @return the factory for sending requests into the domain.
0050      */
0051     static DomainFacade* getFacade();
0052 
0053     /**
0054      * Attaches a new observer to the model. The observer will be notified when
0055      * something is changed in the model.
0056      * @param o the observer to be attached to the model.
0057      */
0058     void attach(Observer *o);
0059 
0060     /**
0061      * Detaches an observer from the model. The observer will no longer be notified
0062      * when something is changed in the model.
0063      * @param o the observer to be detached from the model.
0064      */
0065     void detach(Observer *o);
0066 
0067     /**
0068      * Registers the GUI frontend which is used to display and update
0069      * a progress bar when running time consuming operations.
0070      * @param frontend the GUI frontend
0071      */
0072     void registerFrontend(Frontend *frontend);
0073 
0074     /**
0075      * Retrieves the registered frontend.
0076      * @return the frontend if it is a valid frontend pointer, NULL otherwise.
0077      */
0078     Frontend* getFrontend();
0079 
0080     /**
0081      * Adds the frames in the vector to the animation model.
0082      * @param scene The index of the scene to add frames to.
0083      * @param frame Where in the scene to add the frames.
0084      * @param frameNames A vector containing the names of the filenames of the
0085      * images to be added as frames to the animation.
0086      */
0087     void addFrames(int scene, int frame,
0088             StringIterator& frameNames);
0089 
0090     /**
0091      * Removes frames from a scene in the animation.
0092      * @param scene The scene from which to remove the frames.
0093      * @param frame The first frame to remove.
0094      * @param count The number of frames to remove.
0095      */
0096     void removeFrames(int scene, int frame, int count);
0097 
0098     /**
0099      * Moves frames from one position in the animation to another.
0100      * @param fromScene The scene from which to move the frames.
0101      * @param fromFrame The first frame within that scene to move.
0102      * @param count The number of frames to move; all frames moved must be
0103      * within the same scene.
0104      * @param fromScene The scene to move the frames to.
0105      * @param toFrame The position within the scene {@a toScene} to which
0106      * the frames should be moved.
0107      */
0108     void moveFrames(int fromScene, int fromFrame,
0109             int count, int toScene, int toFrame);
0110 
0111     /**
0112      * Duplicates the image file of the specified frame, setting the image to
0113      * the duplicate. This is used when the image is to be edited so that the
0114      * edit can be undone and so that shared images are unshared.
0115      * @param scene The index of the scene to which the frame belongs.
0116      * @param frame The index of the frame within the scene.
0117      */
0118     void duplicateImage(int scene, int frame);
0119 
0120     /**
0121      * Returns the image file for the frame specified.
0122      * @param scene The scene to which the frame belongs.
0123      * @param frame The frame number to examine.
0124      * @return The path to the image file for this frame. Ownership is not
0125      * returned.
0126      */
0127     const char* getImagePath(int scene, int frame);
0128 
0129     /**
0130      * Adds a sound the given frame number. An error message will be
0131      * sent to the frontend if somethings goes wrong with the adding.
0132      * @param sceneNumber The scene containing the frame to which a sound
0133      * will be added.
0134      * @param frameNumber the number of the frame to add the sound to
0135      * @param filename the path to the file with the sound
0136      */
0137     void addSound(int sceneNumber, int frameNumber, const char* filename);
0138 
0139     /**
0140      * Removes the sound with index soundNumber from the frame with index
0141      * frameNumber.
0142      * @param sceneNumber The scene containing the frame from which a sound
0143      * is to be removed.
0144      * @param frameNumber the index of the frame to remove a sound from.
0145      * @param soundNumber the index of the sound to remove from the frame.
0146      */
0147     void removeSound(int sceneNumber, int frameNumber, int soundNumber);
0148 
0149     /**
0150      * Sets the name of the sound with index soundNumber in the frame with
0151      * index frameNumber to soundName.
0152      * @param sceneNumber The scene containing the frame containing the sound
0153      * to be renamed.
0154      * @param frameNumber the index of the frame the sound is in.
0155      * @param soundNumber the index to the sound to change the name of.
0156      * @param soundName the new name of the sound.
0157      */
0158     void setSoundName(int sceneNumber, int frameNumber, int soundNumber,
0159             const char* soundName);
0160 
0161     /**
0162      * Returns the name of a sound attached to a frame in the active scene.
0163      * @param sceneNumber The scene containing the frame to query.
0164      * @param frameNumber The frame within the scene {@a sceneNumber}.
0165      * @param The number of the sound whose name is to be returned.
0166      * @return The sound name. Ownership is not returned.
0167      */
0168     const char* getSoundName(int sceneNumber, int frameNumber,
0169             int soundNumber) const;
0170 
0171     /**
0172      * Returns the number of sounds attached to the frame specified.
0173      * @param scene The scene that the frame belongs to.
0174      * @param frame The frame within that scene.
0175      * @return The number of sounds attached to frame number {@a frame} of
0176      * scene number {@a scene}.
0177      */
0178     int soundCount(int scene, int frame) const;
0179 
0180     /**
0181      * Play the sounds in the specified frame.
0182      * @param scene The scene that the frame belongs to.
0183      * @param frame The frame within that scene.
0184      */
0185     void playSounds(int scene, int frame) const;
0186 
0187     /**
0188      * Loads the project from the {@c .dat} XML file specified. Used for
0189      * recovering from the {@c new.dat} and {@c current.dat} files.
0190      * @param datFilename The XML file to load.
0191      * @param projectFilename The name of the {@c .sto} file that this XML file
0192      * came from or was last saved into, if known. Null if this is unknown. It
0193      * does not matter if this file still exists or not; it will not be
0194      * accessed in this operation, it is simply to set the default name to save
0195      * to and main window title.
0196      * @return {@c true} if successful.
0197      */
0198     bool loadProject(const char* datFilename, const char* projectFilename);
0199 
0200     /**
0201      * Replay commands from the log.
0202      * @param filename Filename of the log.
0203      * @return {@c true} if successful.
0204      */
0205     bool replayCommandLog(const char* filename);
0206 
0207     /**
0208      * Opens a project.
0209      * @param filename The file to load
0210      */
0211     void openProject(const char *filename);
0212 
0213     /**
0214      * Saves the active project to a XML-file which is written to disk.
0215      */
0216     void saveProject(const char *filename);
0217 
0218     /**
0219      * Creates a new project.
0220      */
0221     bool newProject();
0222 
0223     /**
0224      * Checks if there are unsaved changes in the model.
0225      * @return true if there are unsaved changes, false otherwise.
0226      */
0227     bool isUnsavedChanges();
0228 
0229     /**
0230      * Retrieves the size of the model
0231      * @return the size of the model
0232      */
0233     int getModelSize() const;
0234 
0235     /**
0236      * Function for retrieving number of frames in a given scene.
0237      * @param sceneNumber the scene number
0238      * @return number of frames
0239      */
0240     int getSceneSize(int sceneNumber) const;
0241 
0242     /**
0243      * Function for retrieving number of scenes.
0244      * @return number of scenes
0245      */
0246     int getNumberOfScenes() const;
0247 
0248     /**
0249      * Returns the number of sounds attached to a frame
0250      * @param scene The index of the scene containing the frame.
0251      * @param frame The index within the scene of the frame.
0252      * @return The number of sounds belonging to the specified frame.
0253      */
0254     int getNumberOfSounds(int scene, int frame) const;
0255 
0256     /**
0257      * Retrieves the project file.
0258      * @return The project file if it has been set, NULL otherwise.
0259      */
0260     const char* getProjectFile();
0261 
0262     /**
0263      * Sets the preferences in the preferences file for current,
0264      * most recent, second most recent and third most recent project filenames.
0265      */
0266     void setMostRecentProject();
0267 
0268     /**
0269      * Undoes the last undoable operation on the model.
0270      */
0271     void undo();
0272 
0273     /**
0274      * Redoes the last undo operation.
0275      */
0276     void redo();
0277 
0278     /**
0279      * Detects if undo is possible.
0280      */
0281     bool canUndo();
0282 
0283     /**
0284      * Detects if redo is possible.
0285      */
0286     bool canRedo();
0287 
0288     /**
0289      * Clears the undo history.
0290      */
0291     void clearHistory();
0292 
0293     /**
0294      * Sets the observer to receive notification of when the can undo/can redo
0295      * state changes.
0296      */
0297     void setUndoRedoObserver(UndoRedoObserver* observer);
0298 
0299     /**
0300      * Creates a new scene in the animation project.
0301      * @param index the place the new scene should be added to.
0302      */
0303     void newScene(int index);
0304 
0305     /**
0306      * Removes the scene at the location sceneNumber from the animation.
0307      * @param sceneNumber the scene to be removed from the animation.
0308      */
0309     void removeScene(int sceneNumber);
0310 
0311     /**
0312      * Moves the scene at position sceneNumber to the position movePosition.
0313      * @param sceneNumber the number of the scene to move.
0314      * @param movePosition the position to move the scene to.
0315      */
0316     void moveScene(int sceneNumber, int movePosition);
0317 
0318     /**
0319      * Initializes the audio device so it is ready to play sounds. It will sends
0320      * an error message to the frontend if somethings goes wrong, and audio will
0321      * be disabled until the problem is fixed.
0322      * @return true on success, false otherwise
0323      */
0324     bool initAudioDevice();
0325 
0326     /**
0327      * Shutdowns the audio device so other programs can use it.
0328      */
0329     void shutdownAudioDevice();
0330 
0331     /**
0332      * Exports the current project to a video file as specified by the video encoder.
0333      * @param encoder The encoder to be used for video export
0334      * @param playbackSpeed The frame rate (in frames per second) at which
0335      * the video should be encoded, assuming the video encoder supports
0336      * this adjustment.
0337      * @return true on success, false otherwise
0338      */
0339     bool exportToVideo(VideoEncoder *encoder, int playbackSpeed);
0340 
0341     /**
0342      * Exports the current project to a Cinerella project.
0343      * @param file the Cinerella project file
0344      * @return true on success, false otherwise
0345      */
0346     bool exportToCinerella(const char *file);
0347 
0348     /**
0349      * Returns available grabber devices.
0350      * @return vector containing available devices.
0351      */
0352     const std::vector<GrabberDevice> getGrabberDevices();
0353 
0354     /**
0355      * Sets up the command logger file. If unsuccessful, a message will have
0356      * been displayed to the user.
0357      */
0358     void initializeCommandLoggerFile();
0359 
0360 protected:
0361     /**
0362      * The constructor. It is protected so that it will be impossible for other classes,
0363      * classes that don't inherit from it to instantiate the singleton.
0364      */
0365     DomainFacade();
0366 
0367 private:
0368     /**The singleton instance of this class.*/
0369     static DomainFacade *domainFacade;
0370 
0371     /**The datamodel in the program*/
0372     Animation *animationModel;
0373 };
0374 
0375 #endif