1 /****************************************************************************
2 ** $Id: rs_actiondimangular.cpp 1134 2004-07-13 23:26:13Z 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_actiondimangular.h"
29 #include "rs_creation.h"
30 #include "rs_information.h"
31 #include "rs_snapper.h"
32 #include "rs_dialogfactory.h"
36 RS_ActionDimAngular::RS_ActionDimAngular(
37 RS_EntityContainer& container,
38 RS_GraphicView& graphicView)
39 :RS_ActionDimension("Draw Angular Dimensions",
40 container, graphicView) {
44 QAction * RS_ActionDimAngular::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
46 QAction * action = new QAction(tr("&Angular"), 0);
47 // QAction* action = new QAction(tr("Angular"), tr("&Angular"),
48 // QKeySequence(), NULL);
49 action->setStatusTip(tr("Angular Dimension"));
55 void RS_ActionDimAngular::reset() {
56 RS_ActionDimension::reset();
58 edata = RS_DimAngularData(Vector(false),
64 center = Vector(false);
65 RS_DIALOGFACTORY->requestOptions(this, true, true);
70 void RS_ActionDimAngular::trigger() {
71 RS_PreviewActionInterface::trigger();
73 if (line1!=NULL && line2!=NULL) {
74 RS_DimAngular* newEntity = NULL;
76 newEntity = new RS_DimAngular(container,
80 newEntity->setLayerToActive();
81 newEntity->setPenToActive();
83 container->addEntity(newEntity);
87 document->startUndoCycle();
88 document->addUndoable(newEntity);
89 document->endUndoCycle();
92 Vector rz = graphicView->getRelativeZero();
93 graphicView->moveRelativeZero(Vector(0.0,0.0));
94 graphicView->drawEntity(newEntity);
95 graphicView->moveRelativeZero(rz);
98 RS_DEBUG->print("RS_ActionDimAngular::trigger:"
105 void RS_ActionDimAngular::mouseMoveEvent(QMouseEvent* e) {
106 RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent begin");
108 Vector mouse(graphicView->toGraphX(e->x()),
109 graphicView->toGraphY(e->y()));
111 switch (getStatus()) {
119 if (line1!=NULL && line2!=NULL && center.valid) {
120 Vector mouse = snapPoint(e);
121 edata.definitionPoint4 = mouse;
123 RS_DimAngular* d = new RS_DimAngular(preview, data, edata);
128 preview->addEntity(d);
137 RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent end");
142 void RS_ActionDimAngular::mouseReleaseEvent(QMouseEvent* e) {
144 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
145 switch (getStatus()) {
147 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
149 en->rtti()==RS2::EntityLine) {
150 line1 = (RS_Line*)en;
157 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
159 en->rtti()==RS2::EntityLine) {
160 line2 = (RS_Line*)en;
162 VectorSolutions sol =
163 RS_Information::getIntersectionLineLine(line1, line2);
165 if (sol.get(0).valid) {
168 if (center.distanceTo(line1->getStartpoint()) <
169 center.distanceTo(line1->getEndpoint())) {
170 edata.definitionPoint1 = line1->getStartpoint();
171 edata.definitionPoint2 = line1->getEndpoint();
173 edata.definitionPoint1 = line1->getEndpoint();
174 edata.definitionPoint2 = line1->getStartpoint();
177 if (center.distanceTo(line2->getStartpoint()) <
178 center.distanceTo(line2->getEndpoint())) {
179 edata.definitionPoint3 = line2->getStartpoint();
180 data.definitionPoint = line2->getEndpoint();
182 edata.definitionPoint3 = line2->getEndpoint();
183 data.definitionPoint = line2->getStartpoint();
185 graphicView->moveRelativeZero(center);
193 RS_CoordinateEvent ce(snapPoint(e));
194 coordinateEvent(&ce);
198 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
209 void RS_ActionDimAngular::coordinateEvent(RS_CoordinateEvent* e) {
214 switch (getStatus()) {
216 edata.definitionPoint4 = e->getCoordinate();
228 void RS_ActionDimAngular::commandEvent(RS_CommandEvent* e) {
229 QString c = e->getCommand().toLower();
231 if (checkCommand("help", c)) {
232 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
233 + getAvailableCommands().join(", "));
237 // setting new text label:
238 if (getStatus()==SetText) {
240 RS_DIALOGFACTORY->requestOptions(this, true, true);
241 graphicView->enableCoordinateInput();
242 setStatus(lastStatus);
247 if (checkCommand("text", c)) {
248 lastStatus = (Status)getStatus();
249 graphicView->disableCoordinateInput();
256 QStringList RS_ActionDimAngular::getAvailableCommands() {
259 switch (getStatus()) {
263 cmd += command("text");
275 void RS_ActionDimAngular::showOptions() {
276 RS_ActionInterface::showOptions();
278 RS_DIALOGFACTORY->requestOptions(this, true);
283 void RS_ActionDimAngular::hideOptions() {
284 RS_ActionInterface::hideOptions();
286 RS_DIALOGFACTORY->requestOptions(this, false);
291 void RS_ActionDimAngular::updateMouseButtonHints() {
292 switch (getStatus()) {
294 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
298 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
302 RS_DIALOGFACTORY->updateMouseWidget(
303 tr("Specify dimension arc line location"), tr("Cancel"));
306 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
309 RS_DIALOGFACTORY->updateMouseWidget("", "");