]> Shamusworld >> Repos - architektonas/commitdiff
Fixed problem with dimensions not showing up.
authorShamus Hammons <jlhamm@acm.org>
Fri, 30 Jul 2010 01:23:13 +0000 (01:23 +0000)
committerShamus Hammons <jlhamm@acm.org>
Fri, 30 Jul 2010 01:23:13 +0000 (01:23 +0000)
15 files changed:
src/actions/actiondefault.cpp
src/actions/actiondimension.cpp
src/actions/actiondimlinear.cpp
src/actions/actiondimlinear.h
src/base/actioninterface.cpp
src/base/rs_blocklist.cpp
src/base/rs_dimension.cpp
src/base/rs_dimension.h
src/base/rs_dimlinear.cpp
src/base/rs_entitycontainer.cpp
src/base/rs_entitycontainer.h
src/base/rs_font.cpp
src/base/rs_snapper.cpp
src/base/rs_snapper.h
src/base/rs_text.cpp

index 4385c7c0dd9f775551ff4613dbbe9e612ece7b03..ab2c2c348151ae90ead60c3e5d73b6ad74f8948d 100644 (file)
@@ -31,6 +31,9 @@ ActionDefault::ActionDefault(RS_EntityContainer & container,
        container, graphicView)
 {
        RS_DEBUG->print("ActionDefault::ActionDefault");
+       //hm.
+       graphicView.snapper.SetVisible();
+       graphicView.preview.SetVisible();
        RS_DEBUG->print("ActionDefault::ActionDefault: OK");
 }
 
@@ -49,10 +52,13 @@ void ActionDefault::init(int status /*= 0*/)
 
        ActionInterface::init(status);
        v1 = v2 = Vector(false);
-//     snapMode = RS2::SnapFree;
-//     snapRes = RS2::RestrictNothing;
+       graphicView->snapper.setSnapMode(RS2::SnapFree);
+       graphicView->snapper.setSnapRestriction(RS2::RestrictNothing);
        restrBak = RS2::RestrictNothing;
        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
+//hm. Nope.
+//     graphicView->snapper.SetVisible();
+//     graphicView->preview.SetVisible();
 
        RS_DEBUG->print("ActionDefault::init: OK");
 }
@@ -66,15 +72,15 @@ void ActionDefault::keyPressEvent(QKeyEvent * e)
 {
        if (e->key() == Qt::Key_Shift)
        {
-//             restrBak = snapRes;
-//             setSnapRestriction(RS2::RestrictOrthogonal);
+               restrBak = graphicView->snapper.getSnapRestriction();
+               graphicView->snapper.setSnapRestriction(RS2::RestrictOrthogonal);
        }
 }
 
 void ActionDefault::keyReleaseEvent(QKeyEvent * e)
 {
-//     if (e->key() == Qt::Key_Shift)
-//             setSnapRestriction(restrBak);
+       if (e->key() == Qt::Key_Shift)
+               graphicView->snapper.setSnapRestriction(restrBak);
 }
 
 void ActionDefault::mouseMoveEvent(QMouseEvent * e)
@@ -97,8 +103,7 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e)
 
                        if (ref.valid && graphicView->toGuiDX(dist) < 8)
                        {
-                               RS_DEBUG->print("ActionDefault::mouseMoveEvent: "
-                                       "moving reference point");
+                               RS_DEBUG->print("ActionDefault::mouseMoveEvent: moving reference point");
                                setStatus(MovingRef);
                                v1 = ref;
                                graphicView->moveRelativeZero(v1);
@@ -110,8 +115,7 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e)
 
                                if (en && en->isSelected())
                                {
-                                       RS_DEBUG->print("ActionDefault::mouseMoveEvent: "
-                                               "moving entity");
+                                       RS_DEBUG->print("ActionDefault::mouseMoveEvent: moving entity");
                                        setStatus(Moving);
                                        v1 = en->getNearestRef(v1);
                                        graphicView->moveRelativeZero(v1);
@@ -127,21 +131,31 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e)
        case MovingRef:
                v2 = snapPoint(e);
 
-//             deletePreview();
 //             clearPreview();
 //             preview->addSelectionFrom(*container);
 //             preview->moveRef(v1, v2 - v1);
 //             drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addSelectionFrom(*container);
+               graphicView->preview.moveRef(v1, v2 -v1);
+               graphicView->snapper.SetVisible();
+               graphicView->preview.SetVisible();
+               graphicView->redraw();
                break;
 
        case Moving:
                v2 = snapPoint(e);
 
-//             deletePreview();
 //             clearPreview();
 //             preview->addSelectionFrom(*container);
 //             preview->move(v2 - v1);
 //             drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addSelectionFrom(*container);
+               graphicView->preview.move(v2 -v1);
+               graphicView->snapper.SetVisible();
+               graphicView->preview.SetVisible();
+               graphicView->redraw();
                break;
 
        case SetCorner2:
@@ -149,18 +163,19 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e)
                {
                        v2 = mouse;
 
-//                     deletePreview();
-//                     clearPreview();
+                       graphicView->preview.clear();
 
-//                     preview->addEntity(new RS_Line(preview,
-//                             RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
-//                     preview->addEntity(new RS_Line(preview,
-//                             RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
-//                     preview->addEntity(new RS_Line(preview,
-//                             RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
-//                     preview->addEntity(new RS_Line(preview,
-//                             RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
-//                     drawPreview();
+                       graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
+                               RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
+                       graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
+                               RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
+                       graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
+                               RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
+                       graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
+                               RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
+
+                       graphicView->preview.SetVisible();
+                       graphicView->redraw();
                }
 
        default:
@@ -253,7 +268,7 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
                        else
                                setStatus(SetCorner2);
                }
-               break;
+                       break;
 
                case SetCorner2:
                {
@@ -263,6 +278,7 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
 //                     deleteSnapper();
 //                     deletePreview();
 //                     clearPreview();
+                       graphicView->preview.SetVisible(false);
 
                        bool cross = (v2.y > v1.y);
                        RS_Selection s(*container, graphicView);
@@ -273,9 +289,13 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
                        setStatus(Neutral);
                        e->accept();
                }
-               break;
+                       break;
 
                default:
+                       // Was either moving entity or point, so clear that shiatsu
+                       graphicView->snapper.SetVisible(false);
+                       graphicView->preview.SetVisible(false);
+                       graphicView->redraw();
                        break;
                }
        }
index d4d3c66aa5c72f48b567bd336a2b150fc73e41f9..0f1c773b59725972c28906b49c00702c134ada3b 100644 (file)
@@ -30,7 +30,7 @@ ActionDimension::~ActionDimension()
 void ActionDimension::reset()
 {
        data = RS_DimensionData(Vector(false), Vector(false), RS2::VAlignMiddle,
-                       RS2::HAlignCenter, RS2::Exact, 1.0, "", "Standard", 0.0);
+               RS2::HAlignCenter, RS2::Exact, 1.0, "", "Standard", 0.0);
        diameter = false;
 }
 
@@ -43,7 +43,7 @@ void ActionDimension::hideOptions()
 {
        ActionInterface::hideOptions();
 
-       if (RS_DIALOGFACTORY != NULL)
+       if (RS_DIALOGFACTORY)
                RS_DIALOGFACTORY->requestOptions(this, false);
 }
 
@@ -51,7 +51,7 @@ void ActionDimension::showOptions()
 {
        ActionInterface::showOptions();
 
-       if (RS_DIALOGFACTORY != NULL)
+       if (RS_DIALOGFACTORY)
                RS_DIALOGFACTORY->requestOptions(this, true, true);
 }
 
@@ -62,13 +62,13 @@ void ActionDimension::updateMouseCursor()
 
 void ActionDimension::updateToolBar()
 {
-       if (RS_DIALOGFACTORY != NULL)
-       {
-               if (!isFinished())
-                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
-               else
-                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);
-       }
+       if (!RS_DIALOGFACTORY)
+               return;
+
+       if (!isFinished())
+               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+       else
+               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);
 }
 
 QString ActionDimension::getText()
@@ -138,9 +138,8 @@ void ActionDimension::setDiameter(bool d)
 /*static*/ bool ActionDimension::isDimensionAction(RS2::ActionType type)
 {
        return (type == RS2::ActionDimAligned
-               || type == RS2::ActionDimLinear
-               || type == RS2::ActionDimAngular
-               || type == RS2::ActionDimDiametric
-               || type == RS2::ActionDimRadial);
+               || type == RS2::ActionDimLinear
+               || type == RS2::ActionDimAngular
+               || type == RS2::ActionDimDiametric
+               || type == RS2::ActionDimRadial);
 }
-
index fd3583534466fed3e950aea874cecc54ed6e2f49..0a37fe61c255f03e98ceb5e626d2e4754c2a6f32 100644 (file)
  * @param fixedAngle true: The user can't change the angle.
  *                   false: The user can change the angle in a option widget.
  */
-ActionDimLinear::ActionDimLinear(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
+ActionDimLinear::ActionDimLinear(RS_EntityContainer & container,
+       GraphicView & graphicView, double angle, bool fixedAngle):
        ActionDimension("Draw linear dimensions", container, graphicView)
 {
        edata.angle = angle;
        this->fixedAngle = fixedAngle;
        lastStatus = SetExtPoint1;
+       //hm. doesn't work.
+       graphicView.snapper.SetVisible();
        reset();
 }
 
@@ -50,7 +53,7 @@ void ActionDimLinear::reset()
        ActionDimension::reset();
        edata = RS_DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0);
 
-       if (RS_DIALOGFACTORY != NULL)
+       if (RS_DIALOGFACTORY)
                RS_DIALOGFACTORY->requestOptions(this, true, true);
 }
 
@@ -65,19 +68,21 @@ void ActionDimLinear::trigger()
        container->addEntity(dim);
 
        // upd. undo list:
-       if (document != NULL)
+       if (document)
        {
                document->startUndoCycle();
                document->addUndoable(dim);
                document->endUndoCycle();
        }
 
-       deleteSnapper();
-       Vector rz = graphicView->getRelativeZero();
-       graphicView->moveRelativeZero(Vector(0.0, 0.0));
-       graphicView->drawEntity(dim);
-       graphicView->moveRelativeZero(rz);
-       drawSnapper();
+//     deleteSnapper();
+//     Vector rz = graphicView->getRelativeZero();
+//     graphicView->moveRelativeZero(Vector(0.0, 0.0));
+//     graphicView->drawEntity(dim);
+//     graphicView->moveRelativeZero(rz);
+//     drawSnapper();
+       graphicView->snapper.SetVisible(false);
+       graphicView->redraw();
 
        RS_DEBUG->print("ActionDimLinear::trigger(): dim added: %d", dim->getId());
 }
@@ -87,13 +92,10 @@ void ActionDimLinear::preparePreview()
        Vector dirV;
        dirV.setPolar(100.0, edata.angle + M_PI / 2.0);
 
-       RS_ConstructionLine cl(
-               NULL, RS_ConstructionLineData(
-                       edata.extensionPoint2,
-                       edata.extensionPoint2 + dirV));
+       RS_ConstructionLine cl(NULL, RS_ConstructionLineData(edata.extensionPoint2,
+               edata.extensionPoint2 + dirV));
 
-       data.definitionPoint =
-               cl.getNearestPointOnEntity(data.definitionPoint);
+       data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
 }
 
 void ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
@@ -105,35 +107,49 @@ void ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
        switch (getStatus())
        {
        case SetExtPoint1:
+//             graphicView->snapper.SetVisible();
+//             graphicView->redraw();
                break;
 
        case SetExtPoint2:
 
                if (edata.extensionPoint1.valid)
                {
-                       deletePreview();
-                       clearPreview();
+//                     deletePreview();
+//                     clearPreview();
 //                     preview->addEntity(new RS_Line(preview,
 //                             RS_LineData(edata.extensionPoint1, mouse)));
-                       drawPreview();
+//                     drawPreview();
+                       graphicView->preview.clear();
+                       graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
+                               RS_LineData(edata.extensionPoint1, mouse)));
+                       graphicView->preview.SetVisible();
+                       graphicView->redraw();
                }
+
                break;
 
        case SetDefPoint:
 
                if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
                {
-                       deletePreview();
-                       clearPreview();
+//                     deletePreview();
+//                     clearPreview();
                        data.definitionPoint = mouse;
-
-                       preparePreview();
-
+//                     preparePreview();
 //                     RS_DimLinear * dim = new RS_DimLinear(preview, data, edata);
 //                     dim->update();
 //                     preview->addEntity(dim);
-                       drawPreview();
+//                     drawPreview();
+                       graphicView->preview.clear();
+                       preparePreview();
+                       RS_DimLinear * dim = new RS_DimLinear(&(graphicView->preview), data, edata);
+                       dim->update();
+                       graphicView->preview.addEntity(dim);
+                       graphicView->preview.SetVisible();
+                       graphicView->redraw();
                }
+
                break;
        }
 
@@ -146,18 +162,25 @@ void ActionDimLinear::mouseReleaseEvent(QMouseEvent * e)
        {
                Vector ce(snapPoint(e));
                coordinateEvent(&ce);
+               graphicView->snapper.SetVisible();
        }
        else if (e->button() == Qt::RightButton)
        {
-               deletePreview();
-               deleteSnapper();
+               if (getStatus() == 0)
+               {
+                       graphicView->preview.SetVisible(false);
+                       graphicView->snapper.SetVisible(false);
+               }
+
+//             deletePreview();
+//             deleteSnapper();
                init(getStatus() - 1);
        }
 }
 
 void ActionDimLinear::coordinateEvent(Vector * e)
 {
-       if (e == NULL)
+       if (!e)
                return;
 
        Vector pos = *e;
@@ -194,7 +217,7 @@ void ActionDimLinear::commandEvent(RS_CommandEvent * e)
 
        if (checkCommand("help", c))
        {
-               if (RS_DIALOGFACTORY != NULL)
+               if (RS_DIALOGFACTORY)
                        RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
                                + getAvailableCommands().join(", "));
                return;
@@ -205,32 +228,35 @@ void ActionDimLinear::commandEvent(RS_CommandEvent * e)
        case SetText:
                setText(c);
 
-               if (RS_DIALOGFACTORY != NULL)
+               if (RS_DIALOGFACTORY)
                        RS_DIALOGFACTORY->requestOptions(this, true, true);
+
                graphicView->enableCoordinateInput();
                setStatus(lastStatus);
                break;
 
-       case SetAngle: {
+       case SetAngle:
+       {
                bool ok;
                double a = RS_Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                        setAngle(RS_Math::deg2rad(a));
-               else if (RS_DIALOGFACTORY != NULL)
+               else if (RS_DIALOGFACTORY)
                        RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
 
-               if (RS_DIALOGFACTORY != NULL)
+               if (RS_DIALOGFACTORY)
                        RS_DIALOGFACTORY->requestOptions(this, true, true);
+
                setStatus(lastStatus);
        }
-       break;
+               break;
 
        default:
                lastStatus = (Status)getStatus();
-               deleteSnapper();
-               deletePreview();
-               clearPreview();
+//             deleteSnapper();
+//             deletePreview();
+//             clearPreview();
 
                if (checkCommand("text", c))
                {
@@ -240,6 +266,7 @@ void ActionDimLinear::commandEvent(RS_CommandEvent * e)
                }
                else if (!fixedAngle && (checkCommand("angle", c)))
                        setStatus(SetAngle);
+
                break;
        }
 }
@@ -257,6 +284,7 @@ QStringList ActionDimLinear::getAvailableCommands()
 
                if (!fixedAngle)
                        cmd += command("angle");
+
                break;
 
        default:
@@ -268,7 +296,7 @@ QStringList ActionDimLinear::getAvailableCommands()
 
 void ActionDimLinear::updateMouseButtonHints()
 {
-       if (RS_DIALOGFACTORY != NULL)
+       if (RS_DIALOGFACTORY)
        {
                switch (getStatus())
                {
@@ -306,7 +334,7 @@ void ActionDimLinear::showOptions()
 {
        ActionInterface::showOptions();
 
-       if (RS_DIALOGFACTORY != NULL)
+       if (RS_DIALOGFACTORY)
                RS_DIALOGFACTORY->requestOptions(this, true, true);
 }
 
@@ -314,7 +342,7 @@ void ActionDimLinear::hideOptions()
 {
        ActionInterface::hideOptions();
 
-       if (RS_DIALOGFACTORY != NULL)
+       if (RS_DIALOGFACTORY)
                RS_DIALOGFACTORY->requestOptions(this, false);
 }
 
index 60113664c4defd1f917b714933ef95c98263fbb7..bc0ae783be36b90cd864d8f10c801848b023c3be 100644 (file)
@@ -34,7 +34,8 @@ class ActionDimLinear: public ActionDimension
                };
 
        public:
-               ActionDimLinear(RS_EntityContainer & container, GraphicView & graphicView, double angle = 0.0, bool fixedAngle = false);
+               ActionDimLinear(RS_EntityContainer & container, GraphicView & graphicView,
+                       double angle = 0.0, bool fixedAngle = false);
                ~ActionDimLinear();
 
                virtual RS2::ActionType rtti();
@@ -62,7 +63,6 @@ class ActionDimLinear: public ActionDimension
                 * Is the angle fixed?
                 */
                bool fixedAngle;
-
                /** Last status before entering text or angle. */
                Status lastStatus;
 };
index 4280b5c9c8a40f1b9234212b4bcf6f652403f3d5..033fbe1c428e66f3b943ce7a88f3d40b4cf9aa0d 100644 (file)
@@ -43,7 +43,6 @@ ActionInterface::ActionInterface(const char * name, RS_EntityContainer & c,
        this->name = name;
        status = 0;
        finished = false;
-       //triggerOnResume = false;
 
        // Graphic provides a pointer to the graphic if the entity container is a
        //graphic (i.e. can also hold layers).
@@ -52,8 +51,11 @@ ActionInterface::ActionInterface(const char * name, RS_EntityContainer & c,
        // Document pointer will be used for undo / redo
        document = c.getDocument();
 
-       //this->cursor = cursor;
-       //setSnapMode(graphicView.getDefaultSnapMode());
+       // This is here until I can figure out a better way to contain all of this
+       // circular referential nonsense that exists in this codebase. It will be
+       // expunged, by Grabthar's Hammer!
+       graphicView->snapper.SetContainer(container);
+       graphicView->snapper.SetGraphicView(graphicView);       // <-- THIS is what I mean! INSANE!
 
        RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
 }
index fd5dbf59db5296058c1899ddbbe7d8e0912ce862..120f0e5c685b0906d43dea4087672978f64a83e1 100644 (file)
@@ -234,20 +234,16 @@ void RS_BlockList::editBlock(RS_Block* block, const RS_Block& source) {
 RS_Block * RS_BlockList::find(const QString & name)
 {
        //RS_DEBUG->print("RS_BlockList::find");
-       RS_Block * ret = NULL;
 
-       for(uint i=0; i<count(); ++i)
+       for(uint i=0; i<count(); i++)
        {
                RS_Block * b = at(i);
 
                if (b->getName() == name)
-               {
-                       ret = b;
-                       break;
-               }
+                       return b;
        }
 
-       return ret;
+       return NULL;
 }
 
 /**
index 01097c6c6f443ce8ca1a77b21e1815ed81604015..91c49297d59160de3d6e45e41e3164255cfc6a63 100644 (file)
@@ -93,17 +93,17 @@ void RS_Dimension::setLabel(const QString & l)
 void RS_Dimension::updateCreateDimensionLine(const Vector & p1,
        const Vector & p2, bool arrow1, bool arrow2, bool forceAutoText)
 {
+#if 0
+printf("RS_Dimension::updateCreateDimensionLine()...\n");
+#endif
        // text height (DIMTXT)
        double dimtxt = getTextHeight();
        // text distance to line (DIMGAP)
        double dimgap = getDimensionLineGap();
-
        // length of dimension line:
        double distance = p1.distanceTo(p2);
-
        // do we have to put the arrows outside of the line?
-       bool outsideArrows = (distance<getArrowSize()*2.5);
-
+       bool outsideArrows = (distance < getArrowSize() * 2.5);
        // arrow angles:
        double arrowAngle1, arrowAngle2;
 
@@ -113,7 +113,7 @@ void RS_Dimension::updateCreateDimensionLine(const Vector & p1,
        dimensionLine->setLayer(NULL);
        addEntity(dimensionLine);
 
-       if (outsideArrows == false)
+       if (!outsideArrows)
        {
                arrowAngle1 = dimensionLine->getAngle2();
                arrowAngle2 = dimensionLine->getAngle1();
@@ -170,19 +170,14 @@ void RS_Dimension::updateCreateDimensionLine(const Vector & p1,
        else
        {
                textPos = dimensionLine->getMiddlepoint();
-
                Vector distV;
 
                // rotate text so it's readable from the bottom or right (ISO)
                // quadrant 1 & 4
                if (corrected)
-               {
                        distV.setPolar(dimgap + dimtxt / 2.0, dimAngle1 - M_PI / 2.0);
-               }
                else
-               {
                        distV.setPolar(dimgap + dimtxt / 2.0, dimAngle1 + M_PI / 2.0);
-               }
 
                // move text away from dimension line:
                textPos += distV;
@@ -193,6 +188,9 @@ void RS_Dimension::updateCreateDimensionLine(const Vector & p1,
 
        textData = RS_TextData(textPos, dimtxt, 30.0, RS2::VAlignMiddle, RS2::HAlignCenter,
                RS2::LeftToRight, RS2::Exact, 1.0, getLabel(), "standard", textAngle);
+#if 0
+printf("--> %s\n", getLabel().toAscii().data());
+#endif
 
        RS_Text * text = new RS_Text(this, textData);
 
@@ -201,8 +199,7 @@ void RS_Dimension::updateCreateDimensionLine(const Vector & p1,
 
        if (text->getUsedTextWidth() > distance)
        {
-               distH.setPolar(text->getUsedTextWidth() / 2.0
-                       + distance / 2.0 + dimgap, textAngle);
+               distH.setPolar(text->getUsedTextWidth() / 2.0 + distance / 2.0 + dimgap, textAngle);
                text->move(distH);
        }
 
index abb932a7bb36d31331e74ef45710e4fc2f3c38bf..7477a45ce31963096d6638a16df6fbc6e7946331 100644 (file)
@@ -10,28 +10,28 @@ class RS_DimensionData: public RS_Flags
 {
        public:
                /**
-               * Default constructor. Leaves the data object uninitialized.
-               */
+                * Default constructor. Leaves the data object uninitialized.
+                */
                RS_DimensionData() {}
 
                /**
-               * Constructor with initialisation.
-               *
-               * @param definitionPoint Definition point.
-               * @param middleOfText Middle point of dimension text.
-               * @param valign Vertical alignment.
-               * @param halign Horizontal alignment.
-               * @param lineSpacingStyle Line spacing style.
-               * @param lineSpacingFactor Line spacing factor.
-               * @param text Text string entered explicitly by user or null
-               *         or "<>" for the actual measurement or " " (one blank space).
-               *         for supressing the text.
-               * @param style Dimension style name.
-               * @param angle Rotation angle of dimension text away from
-               *         default orientation.
-               */
-               RS_DimensionData(const Vector& definitionPoint,
-                       const Vector& middleOfText,
+                * Constructor with initialisation.
+                *
+                * @param definitionPoint Definition point.
+                * @param middleOfText Middle point of dimension text.
+                * @param valign Vertical alignment.
+                * @param halign Horizontal alignment.
+                * @param lineSpacingStyle Line spacing style.
+                * @param lineSpacingFactor Line spacing factor.
+                * @param text Text string entered explicitly by user or null
+                *         or "<>" for the actual measurement or " " (one blank space).
+                *         for supressing the text.
+                * @param style Dimension style name.
+                * @param angle Rotation angle of dimension text away from
+                *         default orientation.
+                */
+               RS_DimensionData(const Vector & definitionPoint,
+                       const Vector & middleOfText,
                        RS2::VAlign valign,
                        RS2::HAlign halign,
                        RS2::TextLineSpacingStyle lineSpacingStyle,
@@ -77,10 +77,10 @@ class RS_DimensionData: public RS_Flags
                /** Line spacing factor */
                double lineSpacingFactor;
                /**
-               * Text string entered explicitly by user or null
-               * or "<>" for the actual measurement or " " (one blank space)
-               * for supressing the text.
-               */
+                * Text string entered explicitly by user or null
+                * or "<>" for the actual measurement or " " (one blank space)
+                * for supressing the text.
+                */
                QString text;
                /** Dimension style name */
                QString style;
@@ -106,15 +106,15 @@ class RS_Dimension: public RS_EntityContainer
                void setLabel(const QString & l);
 
                /**
-               * Needs to be implemented by the dimension class to return the
-               * measurement of the dimension (e.g. 10.5 or 15'14").
-               */
+                * Needs to be implemented by the dimension class to return the
+                * measurement of the dimension (e.g. 10.5 or 15'14").
+                */
                virtual QString getMeasuredLabel() = 0;
 
                /**
-               * Must be overwritten by implementing dimension entity class
-               * to update the subentities which make up the dimension entity.
-               */
+                * Must be overwritten by implementing dimension entity class
+                * to update the subentities which make up the dimension entity.
+                */
                virtual void update(bool autoText = false) = 0;
 
                void updateCreateDimensionLine(const Vector & p1, const Vector & p2,
@@ -133,7 +133,7 @@ class RS_Dimension: public RS_EntityContainer
                double getExtensionLineOffset();
                double getDimensionLineGap();
                double getTextHeight();
-               double getGraphicVariable(const QString& key, double defMM, int code);
+               double getGraphicVariable(const QString & key, double defMM, int code);
                virtual double getLength();
                virtual void move(Vector offset);
                virtual void rotate(Vector center, double angle);
index 9797e36549db66e3e679f50b3a4b9589aa786677..6d587ef7f8f69ae9fbf35fd8916c5c18d1f89f7f 100644 (file)
@@ -95,15 +95,11 @@ QString RS_DimLinear::getMeasuredLabel()
 
        QString ret;
 
-       if (graphic != NULL)
-       {
+       if (graphic)
                ret = RS_Units::formatLinear(dist, graphic->getUnit(),
                        graphic->getLinearFormat(), graphic->getLinearPrecision());
-       }
        else
-       {
                ret = QString("%1").arg(dist);
-       }
 //It's properly creating the label...
 //printf("RS_DimLinear::getMeasuredLabel: label=\"%s\"\n", ret.toAscii().data());
 
@@ -137,7 +133,7 @@ void RS_DimLinear::update(bool autoText)
        double dimexe = getExtensionLineExtension();
 
        RS_LineData ld;
-       double extAngle = edata.angle + (M_PI/2.0);
+       double extAngle = edata.angle + (M_PI / 2.0);
 
        // direction of dimension line
        Vector dirDim;
index 94f3a4ceb09aa4382b809454d930436bb49a5b70..89bfa8f15ea51be9ccdc02586a1e30e12aff6eb9 100644 (file)
@@ -1191,284 +1191,221 @@ Vector RS_EntityContainer::getNearestEndpoint(const Vector & coord, double * dis
     return closestPoint;
 }
 
+Vector RS_EntityContainer::getNearestPointOnEntity(const Vector & coord,
+       bool onEntity, double * dist, RS_Entity ** entity)
+{
+       Vector point(false);
 
+       RS_Entity * e = getNearestEntity(coord, dist, RS2::ResolveNone);
 
-Vector RS_EntityContainer::getNearestPointOnEntity(const Vector& coord,
-        bool onEntity, double* dist, RS_Entity** entity) {
-
-    Vector point(false);
-
-    RS_Entity* e = getNearestEntity(coord, dist, RS2::ResolveNone);
-
-    if (e!=NULL && e->isVisible()) {
-        point = e->getNearestPointOnEntity(coord, onEntity, dist, entity);
-    }
+       if (e && e->isVisible())
+               point = e->getNearestPointOnEntity(coord, onEntity, dist, entity);
 
-    return point;
+       return point;
 }
 
+Vector RS_EntityContainer::getNearestCenter(const Vector & coord, double * dist)
+{
+       Vector point(false);
+       RS_Entity * closestEntity = getNearestEntity(coord, NULL, RS2::ResolveNone);
 
+       if (closestEntity)
+               point = closestEntity->getNearestCenter(coord, dist);
 
-Vector RS_EntityContainer::getNearestCenter(const Vector& coord,
-        double* dist) {
-
-    Vector point(false);
-    RS_Entity* closestEntity;
-
-    //closestEntity = getNearestEntity(coord, NULL, RS2::ResolveAll);
-    closestEntity = getNearestEntity(coord, NULL, RS2::ResolveNone);
-
-    if (closestEntity!=NULL) {
-        point = closestEntity->getNearestCenter(coord, dist);
-    }
-
-    return point;
+       return point;
 }
 
+Vector RS_EntityContainer::getNearestMiddle(const Vector & coord, double * dist)
+{
+       Vector point(false);
+       RS_Entity * closestEntity = getNearestEntity(coord, NULL, RS2::ResolveNone);
 
+       if (closestEntity)
+               point = closestEntity->getNearestMiddle(coord, dist);
 
-Vector RS_EntityContainer::getNearestMiddle(const Vector& coord,
-        double* dist) {
-
-    Vector point(false);
-    RS_Entity* closestEntity;
-
-    closestEntity = getNearestEntity(coord, NULL, RS2::ResolveNone);
-
-    if (closestEntity!=NULL) {
-        point = closestEntity->getNearestMiddle(coord, dist);
-    }
-
-    return point;
-
-
-    /*
-       double minDist = RS_MAXDOUBLE;  // minimum measured distance
-       double curDist;                 // currently measured distance
-       Vector closestPoint;         // closest found endpoint
-       Vector point;                // endpoint found
-
-       for (RS_Entity* en = firstEntity();
-               en != NULL;
-               en = nextEntity()) {
-
-           if (en->isVisible()) {
-               point = en->getNearestMiddle(coord, &curDist);
-               if (curDist<minDist) {
-                   closestPoint = point;
-                   minDist = curDist;
-                   if (dist!=NULL) {
-                       *dist = curDist;
-                   }
-               }
-           }
-       }
-
-       return closestPoint;
-    */
+       return point;
 }
 
+Vector RS_EntityContainer::getNearestDist(double distance, const Vector & coord,
+       double * dist)
+{
+       Vector point(false);
+       RS_Entity * closestEntity = getNearestEntity(coord, NULL, RS2::ResolveNone);
 
+       if (closestEntity)
+               point = closestEntity->getNearestDist(distance, coord, dist);
 
-Vector RS_EntityContainer::getNearestDist(double distance,
-        const Vector& coord,
-        double* dist) {
-
-    Vector point(false);
-    RS_Entity* closestEntity;
-
-    closestEntity = getNearestEntity(coord, NULL, RS2::ResolveNone);
-
-    if (closestEntity!=NULL) {
-        point = closestEntity->getNearestDist(distance, coord, dist);
-    }
-
-    return point;
+       return point;
 }
 
-
-
 /**
  * @return The intersection which is closest to 'coord'
  */
-Vector RS_EntityContainer::getNearestIntersection(const Vector& coord,
-        double* dist) {
-
-    double minDist = RS_MAXDOUBLE;  // minimum measured distance
-    double curDist;                 // currently measured distance
-    Vector closestPoint(false); // closest found endpoint
-    Vector point;                // endpoint found
-    VectorSolutions sol;
-    RS_Entity* closestEntity;
-
-    closestEntity = getNearestEntity(coord, NULL, RS2::ResolveAll);
-
-    if (closestEntity!=NULL) {
-        for (RS_Entity* en = firstEntity(RS2::ResolveAll);
-                en != NULL;
-                en = nextEntity(RS2::ResolveAll)) {
-
-            if (en->isVisible() && en!=closestEntity) {
-                sol = RS_Information::getIntersection(closestEntity,
-                                                      en,
-                                                      true);
-
-                for (int i=0; i<4; i++) {
-                    point = sol.get(i);
-                    if (point.valid) {
-                        curDist = coord.distanceTo(point);
-
-                        if (curDist<minDist) {
-                            closestPoint = point;
-                            minDist = curDist;
-                            if (dist!=NULL) {
-                                *dist = curDist;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        //}
-    }
-
-    return closestPoint;
-}
+Vector RS_EntityContainer::getNearestIntersection(const Vector & coord,
+       double * dist)
+{
+       double minDist = RS_MAXDOUBLE;                          // minimum measured distance
+       double curDist;                                                         // currently measured distance
+       Vector closestPoint(false);                                     // closest found endpoint
+       Vector point;                                                           // endpoint found
+       VectorSolutions sol;
+       RS_Entity * closestEntity;
 
+       closestEntity = getNearestEntity(coord, NULL, RS2::ResolveAll);
 
+       if (closestEntity)
+       {
+               for(RS_Entity * en=firstEntity(RS2::ResolveAll); en!=NULL;
+                       en = nextEntity(RS2::ResolveAll))
+               {
+                       if (en->isVisible() && en!=closestEntity)
+                       {
+                               sol = RS_Information::getIntersection(closestEntity, en, true);
 
-Vector RS_EntityContainer::getNearestRef(const Vector& coord,
-        double* dist) {
+                               for(int i=0; i<4; i++)
+                               {
+                                       point = sol.get(i);
 
-    double minDist = RS_MAXDOUBLE;  // minimum measured distance
-    double curDist;                 // currently measured distance
-    Vector closestPoint(false);  // closest found endpoint
-    Vector point;                // endpoint found
+                                       if (point.valid)
+                                       {
+                                               curDist = coord.distanceTo(point);
 
-    for (RS_Entity* en = firstEntity();
-            en != NULL;
-            en = nextEntity()) {
+                                               if (curDist < minDist)
+                                               {
+                                                       closestPoint = point;
+                                                       minDist = curDist;
 
-        if (en->isVisible()) {
-            point = en->getNearestRef(coord, &curDist);
-            if (point.valid && curDist<minDist) {
-                closestPoint = point;
-                minDist = curDist;
-                if (dist!=NULL) {
-                    *dist = curDist;
-                }
-            }
-        }
-    }
+                                                       if (dist)
+                                                               *dist = curDist;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
 
-    return closestPoint;
+       return closestPoint;
 }
 
+Vector RS_EntityContainer::getNearestRef(const Vector & coord, double * dist)
+{
+       double minDist = RS_MAXDOUBLE;  // minimum measured distance
+       double curDist;                 // currently measured distance
+       Vector closestPoint(false);  // closest found endpoint
+       Vector point;                // endpoint found
 
-Vector RS_EntityContainer::getNearestSelectedRef(const Vector& coord,
-        double* dist) {
-
-    double minDist = RS_MAXDOUBLE;  // minimum measured distance
-    double curDist;                 // currently measured distance
-    Vector closestPoint(false);  // closest found endpoint
-    Vector point;                // endpoint found
+       for(RS_Entity * en=firstEntity(); en!=NULL; en=nextEntity())
+       {
+               if (en->isVisible())
+               {
+                       point = en->getNearestRef(coord, &curDist);
 
-    for (RS_Entity* en = firstEntity();
-            en != NULL;
-            en = nextEntity()) {
+                       if (point.valid && curDist < minDist)
+                       {
+                               closestPoint = point;
+                               minDist = curDist;
 
-        if (en->isVisible() && en->isSelected() && !en->isParentSelected()) {
-            point = en->getNearestSelectedRef(coord, &curDist);
-            if (point.valid && curDist<minDist) {
-                closestPoint = point;
-                minDist = curDist;
-                if (dist!=NULL) {
-                    *dist = curDist;
-                }
-            }
-        }
-    }
+                               if (dist)
+                                       *dist = curDist;
+                       }
+               }
+       }
 
-    return closestPoint;
+       return closestPoint;
 }
 
+Vector RS_EntityContainer::getNearestSelectedRef(const Vector & coord,
+       double * dist)
+{
+       double minDist = RS_MAXDOUBLE;                          // minimum measured distance
+       double curDist;                                                         // currently measured distance
+       Vector closestPoint(false);                                     // closest found endpoint
+       Vector point;                                                           // endpoint found
 
-double RS_EntityContainer::getDistanceToPoint(const Vector& coord,
-        RS_Entity** entity,
-        RS2::ResolveLevel level,
-        double solidDist) {
+       for(RS_Entity * en=firstEntity(); en!=NULL; en=nextEntity())
+       {
+               if (en->isVisible() && en->isSelected() && !en->isParentSelected())
+               {
+                       point = en->getNearestSelectedRef(coord, &curDist);
 
-    RS_DEBUG->print("RS_EntityContainer::getDistanceToPoint");
+                       if (point.valid && curDist < minDist)
+                       {
+                               closestPoint = point;
+                               minDist = curDist;
 
-    double minDist = RS_MAXDOUBLE;      // minimum measured distance
-    double curDist;                     // currently measured distance
-    RS_Entity* closestEntity = NULL;    // closest entity found
-    RS_Entity* subEntity = NULL;
+                               if (dist)
+                                       *dist = curDist;
+                       }
+               }
+       }
 
-    //int k=0;
-    for (RS_Entity* e = firstEntity(level);
-            e != NULL;
-            e = nextEntity(level)) {
+       return closestPoint;
+}
 
-        if (e->isVisible()) {
-            RS_DEBUG->print("entity: getDistanceToPoint");
-            RS_DEBUG->print("entity: %d", e->rtti());
-            curDist = e->getDistanceToPoint(coord, &subEntity, level, solidDist);
+double RS_EntityContainer::getDistanceToPoint(const Vector & coord,
+       RS_Entity ** entity, RS2::ResolveLevel level, double solidDist)
+{
+       RS_DEBUG->print("RS_EntityContainer::getDistanceToPoint");
 
-            RS_DEBUG->print("entity: getDistanceToPoint: OK");
+       double minDist = RS_MAXDOUBLE;      // minimum measured distance
+       double curDist;                     // currently measured distance
+       RS_Entity * closestEntity = NULL;    // closest entity found
+       RS_Entity * subEntity = NULL;
 
-            if (curDist<minDist) {
-                if (level!=RS2::ResolveAll) {
-                    closestEntity = e;
-                } else {
-                    closestEntity = subEntity;
-                }
-                minDist = curDist;
-            }
-        }
-    }
-
-    if (entity!=NULL) {
-        *entity = closestEntity;
-    }
-    RS_DEBUG->print("RS_EntityContainer::getDistanceToPoint: OK");
+       //int k=0;
+       for(RS_Entity * e=firstEntity(level); e!=NULL; e=nextEntity(level))
+       {
+               if (e->isVisible())
+               {
+                       RS_DEBUG->print("entity: getDistanceToPoint");
+                       RS_DEBUG->print("entity: %d", e->rtti());
+                       curDist = e->getDistanceToPoint(coord, &subEntity, level, solidDist);
+                       RS_DEBUG->print("entity: getDistanceToPoint: OK");
 
-    return minDist;
-}
+                       if (curDist<minDist)
+                       {
+                               if (level != RS2::ResolveAll)
+                                       closestEntity = e;
+                               else
+                                       closestEntity = subEntity;
 
+                               minDist = curDist;
+                       }
+               }
+       }
 
+       if (entity)
+               *entity = closestEntity;
 
-RS_Entity* RS_EntityContainer::getNearestEntity(const Vector& coord,
-        double* dist,
-        RS2::ResolveLevel level) {
+       RS_DEBUG->print("RS_EntityContainer::getDistanceToPoint: OK");
+       return minDist;
+}
 
-    RS_DEBUG->print("RS_EntityContainer::getNearestEntity");
+RS_Entity * RS_EntityContainer::getNearestEntity(const Vector & coord,
+       double * dist, RS2::ResolveLevel level)
+{
+       RS_DEBUG->print("RS_EntityContainer::getNearestEntity");
+       RS_Entity * e = NULL;
 
-    RS_Entity* e = NULL;
+       // distance for points inside solids:
+       double solidDist = RS_MAXDOUBLE;
 
-    // distance for points inside solids:
-    double solidDist = RS_MAXDOUBLE;
-    if (dist!=NULL) {
-        solidDist = *dist;
-    }
+       if (dist)
+               solidDist = *dist;
 
-    double d = getDistanceToPoint(coord, &e, level, solidDist);
+       double d = getDistanceToPoint(coord, &e, level, solidDist);
 
-    if (e!=NULL && e->isVisible()==false) {
-        e = NULL;
-    }
+       if (e && e->isVisible() == false)
+               e = NULL;
 
-    // if d is negative, use the default distance (used for points inside solids)
-    if (dist!=NULL) {
-        *dist = d;
-    }
-    RS_DEBUG->print("RS_EntityContainer::getNearestEntity: OK");
+       // if d is negative, use the default distance (used for points inside solids)
+       if (dist)
+               *dist = d;
 
-    return e;
+       RS_DEBUG->print("RS_EntityContainer::getNearestEntity: OK");
+       return e;
 }
 
-
-
 /**
  * Rearranges the atomic entities in this container in a way that connected
  * entities are stored in the right order and direction.
@@ -1477,216 +1414,217 @@ RS_Entity* RS_EntityContainer::getNearestEntity(const Vector& coord,
  * @retval true all contours were closed
  * @retval false at least one contour is not closed
  */
-bool RS_EntityContainer::optimizeContours() {
-
-    RS_DEBUG->print("RS_EntityContainer::optimizeContours");
-
-    Vector current(false);
-    Vector start(false);
-    RS_EntityContainer tmp;
-
-    bool changed = false;
-    bool closed = true;
+bool RS_EntityContainer::optimizeContours()
+{
+       RS_DEBUG->print("RS_EntityContainer::optimizeContours");
 
-    for (uint ci=0; ci<count(); ++ci) {
-        RS_Entity* e1=entityAt(ci);
+       Vector current(false);
+       Vector start(false);
+       RS_EntityContainer tmp;
 
-        if (e1!=NULL && e1->isEdge() && !e1->isContainer() &&
-                !e1->isProcessed()) {
+       bool changed = false;
+       bool closed = true;
 
-            RS_AtomicEntity* ce = (RS_AtomicEntity*)e1;
+       for(uint ci=0; ci<count(); ++ci)
+       {
+               RS_Entity * e1=entityAt(ci);
 
-            // next contour start:
-            ce->setProcessed(true);
-            tmp.addEntity(ce->clone());
-            current = ce->getEndpoint();
-            start = ce->getStartpoint();
+               if (e1 && e1->isEdge() && !e1->isContainer() && !e1->isProcessed())
+               {
+                       RS_AtomicEntity * ce = (RS_AtomicEntity *)e1;
 
-            // find all connected entities:
-            bool done;
-            do {
-                done = true;
-                for (uint ei=0; ei<count(); ++ei) {
-                    RS_Entity* e2=entityAt(ei);
+                       // next contour start:
+                       ce->setProcessed(true);
+                       tmp.addEntity(ce->clone());
+                       current = ce->getEndpoint();
+                       start = ce->getStartpoint();
 
-                    if (e2!=NULL && e2->isEdge() && !e2->isContainer() &&
-                            !e2->isProcessed()) {
+                       // find all connected entities:
+                       bool done;
 
-                        RS_AtomicEntity* e = (RS_AtomicEntity*)e2;
+                       do
+                       {
+                               done = true;
+                               for(uint ei=0; ei<count(); ++ei)
+                               {
+                                       RS_Entity * e2=entityAt(ei);
 
-                        if (e->getStartpoint().distanceTo(current) <
-                                1.0e-4) {
+                                       if (e2 != NULL && e2->isEdge() && !e2->isContainer() &&
+                                               !e2->isProcessed())
+                                       {
+                                               RS_AtomicEntity * e = (RS_AtomicEntity *)e2;
 
-                            e->setProcessed(true);
-                            tmp.addEntity(e->clone());
-                            current = e->getEndpoint();
+                                               if (e->getStartpoint().distanceTo(current) < 1.0e-4)
+                                               {
+                                                       e->setProcessed(true);
+                                                       tmp.addEntity(e->clone());
+                                                       current = e->getEndpoint();
+                                                       done = false;
+                                               }
+                                               else if (e->getEndpoint().distanceTo(current) < 1.0e-4)
+                                               {
+                                                       e->setProcessed(true);
+                                                       RS_AtomicEntity * cl = (RS_AtomicEntity *)e->clone();
+                                                       cl->reverse();
+                                                       tmp.addEntity(cl);
+                                                       current = cl->getEndpoint();
+                                                       changed = true;
+                                                       done = false;
+                                               }
+                                       }
+                               }
 
-                            done=false;
-                        } else if (e->getEndpoint().distanceTo(current) <
-                                   1.0e-4) {
+                               if (!done)
+                                       changed = true;
+                       }
+                       while (!done);
 
-                            e->setProcessed(true);
-                            RS_AtomicEntity* cl = (RS_AtomicEntity*)e->clone();
-                            cl->reverse();
-                            tmp.addEntity(cl);
-                            current = cl->getEndpoint();
+                       if (current.distanceTo(start) > 1.0e-4)
+                               closed = false;
+               }
+       }
 
-                            changed = true;
-                            done=false;
-                        }
-                    }
-                }
-                if (!done) {
-                    changed = true;
-                }
-            } while (!done);
+       // remove all atomic entities:
+       bool done;
 
-            if (current.distanceTo(start)>1.0e-4) {
-                closed = false;
-            }
-        }
-    }
+       do
+       {
+               done = true;
 
-    // remove all atomic entities:
-    bool done;
-    do {
-        done = true;
-        for (RS_Entity* en=firstEntity(); en!=NULL; en=nextEntity()) {
-            if (!en->isContainer()) {
-                removeEntity(en);
-                done = false;
-                break;
-            }
-        }
-    } while (!done);
+               for(RS_Entity * en=firstEntity(); en!=NULL; en=nextEntity())
+               {
+                       if (!en->isContainer())
+                       {
+                               removeEntity(en);
+                               done = false;
+                               break;
+                       }
+               }
+       }
+       while (!done);
 
-    // add new sorted entities:
-    for (RS_Entity* en=tmp.firstEntity(); en!=NULL; en=tmp.nextEntity()) {
-        en->setProcessed(false);
-        addEntity(en->clone());
-    }
+       // add new sorted entities:
+       for(RS_Entity * en=tmp.firstEntity(); en!=NULL; en=tmp.nextEntity())
+       {
+               en->setProcessed(false);
+               addEntity(en->clone());
+       }
 
-    RS_DEBUG->print("RS_EntityContainer::optimizeContours: OK");
-    return closed;
+       RS_DEBUG->print("RS_EntityContainer::optimizeContours: OK");
+       return closed;
 }
 
+bool RS_EntityContainer::hasEndpointsWithinWindow(Vector v1, Vector v2)
+{
+       for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+       {
+               if (e->hasEndpointsWithinWindow(v1, v2))
+                       return true;
+       }
 
-bool RS_EntityContainer::hasEndpointsWithinWindow(Vector v1, Vector v2) {
-    for (RS_Entity* e=firstEntity(RS2::ResolveNone);
-            e!=NULL;
-            e=nextEntity(RS2::ResolveNone)) {
-        if (e->hasEndpointsWithinWindow(v1, v2))  {
-            return true;
-        }
-    }
-
-    return false;
+       return false;
 }
 
+void RS_EntityContainer::move(Vector offset)
+{
+       for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+               e->move(offset);
 
-void RS_EntityContainer::move(Vector offset) {
-    for (RS_Entity* e=firstEntity(RS2::ResolveNone);
-            e!=NULL;
-            e=nextEntity(RS2::ResolveNone)) {
-        e->move(offset);
-    }
-    if (autoUpdateBorders) {
-        calculateBorders();
-    }
+       if (autoUpdateBorders)
+               calculateBorders();
 }
 
+void RS_EntityContainer::rotate(Vector center, double angle)
+{
+       for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+               e->rotate(center, angle);
 
-
-void RS_EntityContainer::rotate(Vector center, double angle) {
-    for (RS_Entity* e=firstEntity(RS2::ResolveNone);
-            e!=NULL;
-            e=nextEntity(RS2::ResolveNone)) {
-        e->rotate(center, angle);
-    }
-    if (autoUpdateBorders) {
-        calculateBorders();
-    }
+       if (autoUpdateBorders)
+               calculateBorders();
 }
 
+void RS_EntityContainer::scale(Vector center, Vector factor)
+{
+       if (fabs(factor.x) > RS_TOLERANCE && fabs(factor.y) > RS_TOLERANCE)
+       {
+               for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+                       e->scale(center, factor);
+       }
 
-
-void RS_EntityContainer::scale(Vector center, Vector factor) {
-    if (fabs(factor.x)>RS_TOLERANCE && fabs(factor.y)>RS_TOLERANCE) {
-        for (RS_Entity* e=firstEntity(RS2::ResolveNone);
-                e!=NULL;
-                e=nextEntity(RS2::ResolveNone)) {
-            e->scale(center, factor);
-        }
-    }
-    if (autoUpdateBorders) {
-        calculateBorders();
-    }
+       if (autoUpdateBorders)
+               calculateBorders();
 }
 
-
-
-void RS_EntityContainer::mirror(Vector axisPoint1, Vector axisPoint2) {
-    if (axisPoint1.distanceTo(axisPoint2)>1.0e-6) {
-        for (RS_Entity* e=firstEntity(RS2::ResolveNone);
-                e!=NULL;
-                e=nextEntity(RS2::ResolveNone)) {
-            e->mirror(axisPoint1, axisPoint2);
-        }
-    }
+void RS_EntityContainer::mirror(Vector axisPoint1, Vector axisPoint2)
+{
+       if (axisPoint1.distanceTo(axisPoint2) > 1.0e-6)
+       {
+               for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+                       e->mirror(axisPoint1, axisPoint2);
+       }
 }
 
+void RS_EntityContainer::stretch(Vector firstCorner, Vector secondCorner,
+       Vector offset)
+{
+       if (getMin().isInWindow(firstCorner, secondCorner) &&
+               getMax().isInWindow(firstCorner, secondCorner))
+       {
+               move(offset);
+       }
+       else
+       {
+               for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+                       e->stretch(firstCorner, secondCorner, offset);
+       }
 
-void RS_EntityContainer::stretch(Vector firstCorner,
-                                 Vector secondCorner,
-                                 Vector offset) {
-
-    if (getMin().isInWindow(firstCorner, secondCorner) &&
-            getMax().isInWindow(firstCorner, secondCorner)) {
-
-        move(offset);
-    } else {
-        for (RS_Entity* e=firstEntity(RS2::ResolveNone);
-                e!=NULL;
-                e=nextEntity(RS2::ResolveNone)) {
-            e->stretch(firstCorner, secondCorner, offset);
-        }
-    }
-
-    // some entitiycontainers might need an update (e.g. RS_Leader):
-    update();
+       // some entitiycontainers might need an update (e.g. RS_Leader):
+       update();
 }
 
+void RS_EntityContainer::moveRef(const Vector & ref, const Vector & offset)
+{
+       for(RS_Entity* e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+               e->moveRef(ref, offset);
 
-
-void RS_EntityContainer::moveRef(const Vector& ref,
-                                 const Vector& offset) {
-
-    for (RS_Entity* e=firstEntity(RS2::ResolveNone);
-            e!=NULL;
-            e=nextEntity(RS2::ResolveNone)) {
-        e->moveRef(ref, offset);
-    }
-    if (autoUpdateBorders) {
-        calculateBorders();
-    }
+       if (autoUpdateBorders)
+               calculateBorders();
 }
 
 void RS_EntityContainer::moveSelectedRef(const Vector & ref, const Vector & offset)
 {
-    for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
-        e->moveSelectedRef(ref, offset);
+       for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+               e->moveSelectedRef(ref, offset);
 
        if (autoUpdateBorders)
-        calculateBorders();
+               calculateBorders();
 }
 
 void RS_EntityContainer::draw(PaintInterface * painter, GraphicView * view, double /*patternOffset*/)
 {
-       if (painter == NULL || view == NULL)
+       if (!painter || !view)
                return;
 
-       for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e = nextEntity(RS2::ResolveNone))
+       for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
+#if 0
+{
+if (e->rtti() == RS2::EntityText)
+{
+       std::cout << "About to draw TEXT entity... "
+               << "TEXT=\"" << ((RS_Text *)e)->getText().toAscii().data() << "\"" << std::endl;
+}
+//OK, we have text, but no insert entities at least none that are drawn...
+//Ah! But with a standard text entity, it DOES have them!
+else if (e->rtti() == RS2::EntityInsert)
+{
+       std::cout << "About to draw INSERT entity... "
+               << "INSERT=\"" << ((RS_Insert *)e)->getData().name.toAscii().data() << "\"" << std::endl;
+}
+#endif
                view->drawEntity(e);
+#if 0
+}
+#endif
 }
 
 /**
@@ -1695,16 +1633,13 @@ void RS_EntityContainer::draw(PaintInterface * painter, GraphicView * view, doub
 std::ostream & operator<<(std::ostream & os, RS_EntityContainer & ec)
 {
        static int indent = 0;
-
        char * tab = new char[indent * 2 + 1];
 
-       for(int i=0; i<indent*2; ++i)
+       for(int i=0; i<indent*2; i++)
                tab[i] = ' ';
 
        tab[indent * 2] = '\0';
-
-       ++indent;
-
+       indent++;
        unsigned long int id = ec.getId();
 
        os << tab << "EntityContainer[" << id << "]: \n";
@@ -1712,10 +1647,10 @@ std::ostream & operator<<(std::ostream & os, RS_EntityContainer & ec)
        << ec.minV << " - " << ec.maxV << "\n";
        //os << tab << "Unit[" << id << "]: "
        //<< RS_Units::unit2string (ec.unit) << "\n";
-       if (ec.getLayer() != NULL)
+       if (ec.getLayer())
        {
                os << tab << "Layer[" << id << "]: "
-               << ec.getLayer()->getName().toLatin1().data() << "\n";
+                       << ec.getLayer()->getName().toLatin1().data() << "\n";
        }
        else
        {
@@ -1762,9 +1697,8 @@ os << s.toAscii().data();
        }
 
        os << tab << "\n\n";
-       --indent;
+       indent--;
 
        delete[] tab;
        return os;
 }
-
index 4e4cf227edfe6e923b0793d69183b19284ceb5cb..a55733e35ecd903a5fdc07b8d548d84da36bac23 100644 (file)
@@ -105,7 +105,6 @@ class RS_EntityContainer: public RS_Entity
 
        protected:
                /** entities in the container */
-//             Q3PtrList<RS_Entity> entities;
                QList<RS_Entity *> entities;
 
                /** sub container used only temporarly for iteration. */
index cd81bb939a9520730242a51ef4b3dfb29fcff2b0..b8a3e6cc1c19b8b7621db9bdbc6061016b39139f 100644 (file)
@@ -119,9 +119,9 @@ bool RS_Font::loadFont()
        }
 
        // Open cxf file:
-       QFile f(path);
+       QFile file(path);
 
-       if (!f.open(QIODevice::ReadOnly))
+       if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        {
                RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Font::loadFont: Cannot open font file: %s",
                        path.toLatin1().data());
@@ -132,14 +132,17 @@ bool RS_Font::loadFont()
                RS_DEBUG->print("RS_Font::loadFont: Successfully opened font file: %s", path.toLatin1().data());
        }
 
-       QTextStream ts(&f);
+       QTextStream ts(&file);
        QString line;
 
        // Read line by line until we find a new letter:
-       while (!f.atEnd())
+//I think this is wrong... We're mixing classes here...
+//AND THAT WAS THE PROBLEM!!!
+//     while (!file.atEnd())
+       while (!ts.atEnd())
        {
                line = ts.readLine();
-
+//printf("\"%s\"\n", line.toAscii().data());
                if (line.isEmpty())
                        continue;
 
@@ -168,6 +171,7 @@ bool RS_Font::loadFont()
                        if (list.size() >= 2)
                                value = list[1].simplified();//.toLower();
 #endif
+//printf("--> identifier=\"%s\", value=\"%s\"\n", identifier.toAscii().data(), value.toAscii().data());
 
                        if (identifier == "letterspacing")
                                letterSpacing = value.toDouble();
@@ -268,7 +272,7 @@ bool RS_Font::loadFont()
                }
        }
 
-       f.close();
+       file.close();
        loaded = true;
 
        RS_DEBUG->print("RS_Font::loadFont OK");
index bbc306cc736098748264ea3b8091b0696b7ba217..30e666436d46e44425ac8b54e636ccbc8aed9364 100644 (file)
@@ -114,11 +114,21 @@ void RS_Snapper::setSnapRestriction(RS2::SnapRestriction snapRes)
        this->snapRes = snapRes;
 }
 
+RS2::SnapMode RS_Snapper::getSnapMode(void)
+{
+       return snapMode;
+}
+
+RS2::SnapRestriction RS_Snapper::getSnapRestriction(void)
+{
+       return snapRes;
+}
+
 /**
-* Sets the snap range in pixels for catchEntity().
-*
-* @see catchEntity()
-*/
+ * Sets the snap range in pixels for catchEntity().
+ *
+ * @see catchEntity()
+ */
 void RS_Snapper::setSnapRange(int r)
 {
        snapRange = r;
@@ -228,7 +238,7 @@ Vector RS_Snapper::snapFree(Vector coord)
 Vector RS_Snapper::snapEndpoint(Vector coord)
 {
        Vector vec(false);
-       vec = container->getNearestEndpoint(coord, NULL/*, &keyEntity*/);
+       vec = container->getNearestEndpoint(coord, NULL);
 
        return vec;
 }
@@ -462,7 +472,8 @@ RS_Entity * RS_Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
  */
 /*virtual*/ void RS_Snapper::suspend()
 {
-       deleteSnapper();
+#warning "!!! This may need to have SetVisibility() called !!!"
+//     deleteSnapper();
        snapSpot = snapCoord = Vector(false);
 }
 
@@ -471,7 +482,8 @@ RS_Entity * RS_Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
  */
 /*virtual*/ void RS_Snapper::resume()
 {
-       drawSnapper();
+#warning "!!! This may need to have SetVisibility() called !!!"
+//     drawSnapper();
 }
 
 /**
@@ -492,88 +504,6 @@ RS_Entity * RS_Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
                RS_DIALOGFACTORY->requestSnapDistOptions(distance, true);
 }
 
-/**
- * Draws the snapper on the screen.
- */
-void RS_Snapper::drawSnapper()
-{
-printf("RS_Snapper::drawSnapper(): Using DEPRECATED function!!!\n");
-       if (!visible)
-               xorSnapper();
-}
-
-/**
- * Deletes the snapper from the screen.
- */
-void RS_Snapper::deleteSnapper()
-{
-printf("RS_Snapper::deleteSnapper(): Using DEPRECATED function!!!\n");
-       if (visible)
-       {
-               xorSnapper();
-               snapSpot = Vector(false);
-               snapCoord = Vector(false);
-       }
-}
-
-/**
- * Draws / deletes the current snapper spot.
- */
-void RS_Snapper::xorSnapper()
-{
-#warning "!!! RS_Snapper::xorSnapper() is DEPRECATED !!!"
-//Not completely true...
-//#warning "!!! xorSnapper() not working AT ALL !!!"
-#if 0
-       if (!finished && snapSpot.valid)
-       {
-               RS_Painter * painter = graphicView->createDirectPainter();
-               painter->setPreviewMode();
-
-               if (snapCoord.valid)
-               {
-                       // snap point
-                       painter->drawCircle(graphicView->toGui(snapCoord), 4);
-
-                       // crosshairs:
-                       if (showCrosshairs == true)
-                       {
-                               painter->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width00, RS2::DashLine));
-                               painter->drawLine(Vector(0, graphicView->toGuiY(snapCoord.y)),
-                                       Vector(graphicView->getWidth(), graphicView->toGuiY(snapCoord.y)));
-                               painter->drawLine(Vector(graphicView->toGuiX(snapCoord.x), 0),
-                                       Vector(graphicView->toGuiX(snapCoord.x), graphicView->getHeight()));
-                       }
-               }
-
-               if (snapCoord.valid && snapCoord != snapSpot)
-               {
-                       painter->drawLine(graphicView->toGui(snapSpot) + Vector(-5, 0),
-                               graphicView->toGui(snapSpot) + Vector(-1, 4));
-                       painter->drawLine(graphicView->toGui(snapSpot) + Vector(0, 5),
-                               graphicView->toGui(snapSpot) + Vector(4, 1));
-                       painter->drawLine(graphicView->toGui(snapSpot) + Vector(5, 0),
-                               graphicView->toGui(snapSpot) + Vector(1, -4));
-                       painter->drawLine(graphicView->toGui(snapSpot) + Vector(0, -5),
-                               graphicView->toGui(snapSpot) + Vector(-4, -1));
-               }
-
-               graphicView->destroyPainter();
-               visible = !visible;
-       }
-//#else
-       if (finished || !snapSpot.valid || !graphicView)
-               return;
-
-       graphicView->SetSnapperDraw(true);
-       graphicView->SetSnapperVars(snapSpot, snapCoord, showCrosshairs);
-//Apparently, this gets hit anyway by the preview code...
-//     graphicView->redraw();
-
-       visible = !visible;
-#endif
-}
-
 void RS_Snapper::SetVisible(bool visibility/*= true*/)
 {
        visible = visibility;
index 575bd7badfe72890408385943bcf1e396873a563..52bd4f791de78ceb8d6c07a8c25e9d66f1548983 100644 (file)
@@ -35,6 +35,8 @@ class RS_Snapper
                RS_Entity * getKeyEntity();
                void setSnapMode(RS2::SnapMode snapMode);
                void setSnapRestriction(RS2::SnapRestriction snapRes);
+               RS2::SnapMode getSnapMode(void);
+               RS2::SnapRestriction getSnapRestriction(void);
                void setSnapRange(int r);
 
                Vector snapPoint(QMouseEvent * e);
@@ -46,7 +48,6 @@ class RS_Snapper
                Vector snapMiddle(Vector coord);
                Vector snapDist(Vector coord);
                Vector snapIntersection(Vector coord);
-               //Vector snapDirect(Vector coord, bool abs);
 
                Vector restrictOrthogonal(Vector coord);
                Vector restrictHorizontal(Vector coord);
@@ -60,8 +61,8 @@ class RS_Snapper
                virtual void hideOptions();
                virtual void showOptions();
 
-               void drawSnapper();
-               void deleteSnapper();
+//             void drawSnapper();
+//             void deleteSnapper();
 
 /*
 How should we handle this? All rendering goes through the GraphicView (QG_GraphicView to be
@@ -92,8 +93,8 @@ for setting the coordinates?
                bool Visible(void);
                void Draw(GraphicView *, PaintInterface *);
 
-       private:
-               void xorSnapper();
+//     private:
+//             void xorSnapper();
 
        protected:
                RS_EntityContainer * container;
index 56a8cf75e5135a847956ef164191610ac9c7d91f..9d1c4066936f850485589f3fb44c64cb38df4dbe 100644 (file)
@@ -61,12 +61,10 @@ int RS_Text::getNumberOfLines()
 {
        int c = 1;
 
-       for(int i=0; i<(int)data.text.length(); ++i)
+       for(int i=0; i<(int)data.text.length(); i++)
        {
                if (data.text.at(i).unicode() == 0x0A)
-               {
                        c++;
-               }
        }
 
        return c;
@@ -79,19 +77,30 @@ int RS_Text::getNumberOfLines()
  */
 void RS_Text::update()
 {
+#if 0
+printf("RS_Text::update(): ");
+#endif
        RS_DEBUG->print("RS_Text::update");
-
        clear();
 
+#if 0
+printf("isUndone=%s, ", (isUndone() ? "true" : "false"));
+#endif
        if (isUndone())
                return;
 
        usedTextWidth = 0.0;
        usedTextHeight = 0.0;
 
+#if 0
+printf("data.style=\"%s\", ", data.style.toAscii().data());
+#endif
        RS_Font * font = RS_FONTLIST->requestFont(data.style);
 
-       if (font == NULL)
+#if 0
+printf("font=%08X\n", (unsigned int)font);
+#endif
+       if (!font)
                return;
 
        Vector letterPos = Vector(0.0, -9.0);
@@ -173,23 +182,17 @@ void RS_Text::update()
 
                                // add texts:
                                RS_Text * upper = new RS_Text(oneLine,
-                                       RS_TextData(letterPos + Vector(0.0, 9.0),
-                                               4.0, 100.0, RS2::VAlignTop,
-                                               RS2::HAlignLeft,
-                                               RS2::LeftToRight, RS2::Exact,
-                                               1.0, up, data.style,
-                                               0.0, RS2::Update));
+                                       RS_TextData(letterPos + Vector(0.0, 9.0), 4.0, 100.0,
+                                               RS2::VAlignTop, RS2::HAlignLeft, RS2::LeftToRight,
+                                               RS2::Exact, 1.0, up, data.style, 0.0, RS2::Update));
                                upper->setLayer(NULL);
                                upper->setPen(RS_Pen(RS2::FlagInvalid));
                                oneLine->addEntity(upper);
 
                                RS_Text * lower = new RS_Text(oneLine,
-                                       RS_TextData(letterPos+Vector(0.0, 4.0),
-                                               4.0, 100.0, RS2::VAlignTop,
-                                               RS2::HAlignLeft,
-                                               RS2::LeftToRight, RS2::Exact,
-                                               1.0, dw, data.style,
-                                               0.0, RS2::Update));
+                                       RS_TextData(letterPos+Vector(0.0, 4.0), 4.0, 100.0,
+                                               RS2::VAlignTop, RS2::HAlignLeft, RS2::LeftToRight,
+                                               RS2::Exact, 1.0, dw, data.style, 0.0, RS2::Update));
                                lower->setLayer(NULL);
                                lower->setPen(RS_Pen(RS2::FlagInvalid));
                                oneLine->addEntity(lower);
@@ -218,14 +221,32 @@ void RS_Text::update()
 
                default:
                {
+// Regular text works because the .style is "normallatin1" while the dimensions are done
+// using "standard"... So that's why it doesn't work.
+// "standard" exists, but it seems that no characters are loaded from it...
+//count() == 0...
+//printf("--> default: pos=%d, char=%04X, font size=%d\n", i, data.text.at(i).unicode(), font->getLetterList()->count());
                        // One Letter:
-                       if (font->findLetter(QString(data.text.at(i))) != NULL)
+//#warning "!!! font->findLetter() not working correctly !!!"
+                       if (font->findLetter(QString(data.text.at(i))))
                        {
-                               RS_DEBUG->print("RS_Text::update: insert a "
-                               "letter at pos: %f/%f", letterPos.x, letterPos.y);
-
+//We ain't getting here:
+/*
+About to draw TEXT entity... TEXT="107.25"
+RS_Dimension::updateCreateDimensionLine()...
+--> 107.25
+RS_Text::update(): isUndone=false, font=094C1020
+--> default: pos=0, char=0031
+--> default: pos=1, char=0030
+--> default: pos=2, char=0037
+--> default: pos=3, char=002E
+--> default: pos=4, char=0032
+--> default: pos=5, char=0035
+*/
+//printf("             char=%s\n", QString(data.text.at(i)).toAscii().data());
+                               RS_DEBUG->print("RS_Text::update: insert a letter at pos: %f/%f", letterPos.x, letterPos.y);
                                RS_InsertData d(QString(data.text.at(i)), letterPos, Vector(1.0, 1.0),
-                                       0.0, 1,1, Vector(0.0, 0.0), font->getLetterList(), RS2::NoUpdate);
+                                       0.0, 1, 1, Vector(0.0, 0.0), font->getLetterList(), RS2::NoUpdate);
 
                                RS_Insert * letter = new RS_Insert(this, d);
                                letter->setPen(RS_Pen(RS2::FlagInvalid));
@@ -237,7 +258,6 @@ void RS_Text::update()
                                //letterWidth = Vector(letter->getSize().x, 0.0);
                                // from 2.0.4.6:
                                Vector letterWidth = Vector(letter->getMax().x - letterPos.x, 0.0);
-
                                oneLine->addEntity(letter);
 
                                // next letter position:
@@ -566,7 +586,6 @@ VectorSolutions RS_Text::getRefPoints()
 
 Vector RS_Text::getNearestRef(const Vector & coord, double * dist)
 {
-       //return getRefPoints().getClosest(coord, dist);
        return RS_Entity::getNearestRef(coord, dist);
 }