1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 
27 
28 #include "rs_previewactioninterface.h"
29 
30 #include "rs_graphicview.h"
31 #include "rs_preview.h"
32 #include "rs_debug.h"
33 
34 /**
35  * Constructor.
36  *
37  * Sets the entity container on which the action class inherited
38  * from this interface operates.
39  */
RS_PreviewActionInterface(const char * name,RS_EntityContainer & container,RS_GraphicView & graphicView)40 RS_PreviewActionInterface::RS_PreviewActionInterface(const char* name,
41 													 RS_EntityContainer& container,
42 													 RS_GraphicView& graphicView) :
43 	RS_ActionInterface(name, container, graphicView)
44   ,preview(new RS_Preview(&container))
45 //  ,offset(new RS_Vector{})
46 {
47 
48     RS_DEBUG->print("RS_PreviewActionInterface::RS_PreviewActionInterface: Setting up action with preview: \"%s\"", name);
49 
50     // preview is linked to the container for getting access to
51     //   document settings / dictionary variables
52 
53     preview->setLayer(NULL);
54     hasPreview = true;
55 
56     RS_DEBUG->print("RS_PreviewActionInterface::RS_PreviewActionInterface: Setting up action with preview: \"%s\": OK", name);
57 }
58 
59 
60 
61 /** Destructor */
~RS_PreviewActionInterface()62 RS_PreviewActionInterface::~RS_PreviewActionInterface() {
63     deletePreview();
64 }
65 
66 
67 
init(int status)68 void RS_PreviewActionInterface::init(int status) {
69     deletePreview();
70     RS_ActionInterface::init(status);
71 }
72 
73 
74 
finish(bool updateTB)75 void RS_PreviewActionInterface::finish(bool updateTB) {
76     deletePreview();
77     RS_ActionInterface::finish(updateTB);
78 }
79 
80 
81 
suspend()82 void RS_PreviewActionInterface::suspend() {
83     RS_ActionInterface::suspend();
84     deletePreview();
85 }
86 
87 
88 
resume()89 void RS_PreviewActionInterface::resume() {
90     RS_ActionInterface::resume();
91     drawPreview();
92 }
93 
94 
95 
trigger()96 void RS_PreviewActionInterface::trigger() {
97     RS_ActionInterface::trigger();
98     deletePreview();
99 }
100 
101 
102 /**
103  * Deletes the preview from the screen.
104  */
deletePreview()105 void RS_PreviewActionInterface::deletePreview() {
106 		if (hasPreview){
107                 //avoid deleting NULL or empty preview
108             preview->clear();
109             hasPreview=false;
110         }
111 	if(!graphicView->isCleanUp()){
112 		graphicView->getOverlayContainer(RS2::ActionPreviewEntity)->clear();
113 	}
114 }
115 
116 
117 
118 /**
119  * Draws / deletes the current preview.
120  */
drawPreview()121 void RS_PreviewActionInterface::drawPreview() {
122 	// RVT_PORT How does offset work??        painter->setOffset(offset);
123 	RS_EntityContainer *container=graphicView->getOverlayContainer(RS2::ActionPreviewEntity);
124 	container->clear();
125 	container->setOwner(false); // Little hack for now so we don't delete the preview twice
126 	container->addEntity(preview.get());
127 	graphicView->redraw(RS2::RedrawOverlay);
128 	hasPreview=true;
129 }
130 
131