1 /****************************************************************************
2 ** $Id: rs_actionblocksinsert.cpp 1148 2004-09-11 21:38:11Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actionblocksinsert.h"
29 #include "rs_creation.h"
31 #include "rs_modification.h"
37 RS_ActionBlocksInsert::RS_ActionBlocksInsert(RS_EntityContainer& container,
38 RS_GraphicView& graphicView)
39 :RS_PreviewActionInterface("Blocks Insert",
40 container, graphicView) {}
44 RS_ActionBlocksInsert::~RS_ActionBlocksInsert() {}
46 QAction* RS_ActionBlocksInsert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
48 QAction * action = new QAction(tr("&Insert Block"), 0);
49 // QAction* action = new QAction(tr("Insert Block"), tr("&Insert Block"),
50 // QKeySequence(), NULL);
51 action->setStatusTip(tr("Insert Block"));
56 void RS_ActionBlocksInsert::init(int status) {
57 RS_PreviewActionInterface::init(status);
62 block = graphic->getActiveBlock();
64 data.name = block->getName();
73 void RS_ActionBlocksInsert::reset() {
74 data = RS_InsertData("",
86 void RS_ActionBlocksInsert::trigger() {
91 //RS_Modification m(*container, graphicView);
92 //m.paste(data.insertionPoint);
93 //std::cout << *RS_Clipboard::instance();
96 RS_Creation creation(container, graphicView);
97 data.updateMode = RS2::Update;
98 creation.createInsert(data);
101 graphicView->redraw();
106 void RS_ActionBlocksInsert::mouseMoveEvent(QMouseEvent* e) {
107 switch (getStatus()) {
109 data.insertionPoint = snapPoint(e);
114 //preview->addAllFrom(*block);
115 //preview->move(data.insertionPoint);
116 RS_Creation creation(preview, NULL, false);
117 // Create insert as preview only
118 data.updateMode = RS2::PreviewUpdate;
119 creation.createInsert(data);
131 void RS_ActionBlocksInsert::mouseReleaseEvent(QMouseEvent* e) {
132 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
133 RS_CoordinateEvent ce(snapPoint(e));
134 coordinateEvent(&ce);
135 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
143 void RS_ActionBlocksInsert::coordinateEvent(RS_CoordinateEvent* e) {
148 data.insertionPoint = e->getCoordinate();
154 void RS_ActionBlocksInsert::commandEvent(RS_CommandEvent* e) {
155 QString c = e->getCommand().toLower();
157 if (checkCommand("help", c)) {
158 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
159 + getAvailableCommands().join(", "));
163 switch (getStatus()) {
165 if (checkCommand("angle", c)) {
169 lastStatus = (Status)getStatus();
171 } else if (checkCommand("factor", c)) {
175 lastStatus = (Status)getStatus();
176 setStatus(SetFactor);
177 } else if (checkCommand("columns", c)) {
181 lastStatus = (Status)getStatus();
182 setStatus(SetColumns);
183 } else if (checkCommand("rows", c)) {
187 lastStatus = (Status)getStatus();
189 } else if (checkCommand("columnspacing", c)) {
193 lastStatus = (Status)getStatus();
194 setStatus(SetColumnSpacing);
195 } else if (checkCommand("rowspacing", c)) {
199 lastStatus = (Status)getStatus();
200 setStatus(SetRowSpacing);
206 double a = RS_Math::eval(c, &ok);
208 data.angle = RS_Math::deg2rad(a);
210 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
212 RS_DIALOGFACTORY->requestOptions(this, true, true);
213 setStatus(lastStatus);
219 double f = RS_Math::eval(c, &ok);
223 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
225 RS_DIALOGFACTORY->requestOptions(this, true, true);
226 setStatus(lastStatus);
232 int cols = (int)RS_Math::eval(c, &ok);
236 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
238 RS_DIALOGFACTORY->requestOptions(this, true, true);
239 setStatus(lastStatus);
245 int rows = (int)RS_Math::eval(c, &ok);
249 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
251 RS_DIALOGFACTORY->requestOptions(this, true, true);
252 setStatus(lastStatus);
256 case SetColumnSpacing: {
258 double cs = (int)RS_Math::eval(c, &ok);
262 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
264 RS_DIALOGFACTORY->requestOptions(this, true, true);
265 setStatus(lastStatus);
269 case SetRowSpacing: {
271 int rs = (int)RS_Math::eval(c, &ok);
275 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
277 RS_DIALOGFACTORY->requestOptions(this, true, true);
278 setStatus(lastStatus);
289 QStringList RS_ActionBlocksInsert::getAvailableCommands() {
292 switch (getStatus()) {
294 cmd += command("angle");
295 cmd += command("factor");
297 cmd += command("columns");
298 cmd += command("rows");
299 cmd += command("columnspacing");
300 cmd += command("rowspacing");
310 void RS_ActionBlocksInsert::showOptions() {
311 RS_ActionInterface::showOptions();
313 RS_DIALOGFACTORY->requestOptions(this, true);
318 void RS_ActionBlocksInsert::hideOptions() {
319 RS_ActionInterface::hideOptions();
321 RS_DIALOGFACTORY->requestOptions(this, false);
325 void RS_ActionBlocksInsert::updateMouseButtonHints() {
326 switch (getStatus()) {
328 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
332 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"),
336 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"),
340 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter columns:"),
344 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rows:"),
347 case SetColumnSpacing:
348 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter column spacing:"),
352 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter row spacing:"),
356 RS_DIALOGFACTORY->updateMouseWidget("", "");
363 void RS_ActionBlocksInsert::updateMouseCursor() {
364 graphicView->setMouseCursor(RS2::CadCursor);
369 void RS_ActionBlocksInsert::updateToolBar() {
371 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
373 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);