]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionblockscreate.cpp
Initial import
[architektonas] / src / actions / rs_actionblockscreate.cpp
1 /****************************************************************************
2 ** $Id: rs_actionblockscreate.cpp 1134 2004-07-13 23:26:13Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use 
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionblockscreate.h"
28
29 #include "rs_creation.h"
30 #include "rs_insert.h"
31 #include "rs_modification.h"
32
33 /**
34  * Constructor.
35  */
36 RS_ActionBlocksCreate::RS_ActionBlocksCreate(RS_EntityContainer& container,
37         RS_GraphicView& graphicView)
38         :RS_PreviewActionInterface("Blocks Create",
39                            container, graphicView)
40 {
41     referencePoint = Vector(false);
42 }
43
44
45
46 RS_ActionBlocksCreate::~RS_ActionBlocksCreate() {}
47
48
49
50 QAction* RS_ActionBlocksCreate::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
51 {
52     QAction * action = new QAction(tr("&Create Block"), 0);
53 //    QAction* action = new QAction(tr("Create Block"),
54 //                                  tr("&Create Block"),
55 //                                  QKeySequence(), NULL);
56     action->setStatusTip(tr("Create Block"));
57
58     return action;
59 }
60
61
62
63 void RS_ActionBlocksCreate::init(int status) {
64     RS_PreviewActionInterface::init(status);
65
66 }
67
68
69
70 void RS_ActionBlocksCreate::trigger() {
71     deleteSnapper();
72     //deletePreview();
73     //clearPreview();
74
75     //RS_Modification m(*container, graphicView);
76     //m.paste(data.insertionPoint);
77     //std::cout << *RS_Clipboard::instance();
78
79     if (graphic!=NULL) {
80         RS_BlockList* blockList = graphic->getBlockList();
81         if (blockList!=NULL) {
82             RS_BlockData d =
83                 RS_DIALOGFACTORY->requestNewBlockDialog(blockList);
84
85             if (!d.name.isEmpty()) {
86                 RS_Creation creation(container, graphicView);
87                 creation.createBlock(d, referencePoint, true);
88
89                 RS_InsertData id(
90                     d.name,
91                     referencePoint,
92                     Vector(1.0,1.0),
93                     0.0,
94                     1, 1, Vector(0.0,0.0)
95                 );
96                 creation.createInsert(id);
97             }
98         }
99     }
100
101     graphicView->redraw();
102     finish();
103     graphicView->killSelectActions();
104 }
105
106
107 void RS_ActionBlocksCreate::mouseMoveEvent(QMouseEvent* e) {
108     snapPoint(e);
109
110     switch (getStatus()) {
111     case SetReferencePoint:
112         //data.insertionPoint = snapPoint(e);
113
114         /*if (block!=NULL) {
115             deletePreview();
116             clearPreview();
117             //preview->addAllFrom(*block);
118             //preview->move(data.insertionPoint);
119                 RS_Creation creation(preview, NULL, false);
120                 creation.createInsert(data);
121             drawPreview();
122     }*/
123         break;
124
125     default:
126         break;
127     }
128 }
129
130
131
132 void RS_ActionBlocksCreate::mouseReleaseEvent(QMouseEvent* e) {
133     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
134         RS_CoordinateEvent ce(snapPoint(e));
135         coordinateEvent(&ce);
136     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
137         deleteSnapper();
138         init(getStatus()-1);
139     }
140 }
141
142
143
144 void RS_ActionBlocksCreate::coordinateEvent(RS_CoordinateEvent* e) {
145     if (e==NULL) {
146         return;
147     }
148
149     switch (getStatus()) {
150     case SetReferencePoint:
151         referencePoint = e->getCoordinate();
152         trigger();
153         break;
154
155     default:
156         break;
157
158     }
159 }
160
161
162
163 void RS_ActionBlocksCreate::updateMouseButtonHints() {
164     switch (getStatus()) {
165     case SetReferencePoint:
166         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
167                                             tr("Cancel"));
168         break;
169     default:
170         RS_DIALOGFACTORY->updateMouseWidget("", "");
171         break;
172     }
173 }
174
175
176
177 void RS_ActionBlocksCreate::updateMouseCursor() {
178     graphicView->setMouseCursor(RS2::CadCursor);
179 }
180
181
182
183 void RS_ActionBlocksCreate::updateToolBar() {
184     if (!isFinished()) {
185         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
186     } else {
187         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
188     }
189 }
190
191
192 // EOF