Package cc.sketchchair.sketch

Examples of cc.sketchchair.sketch.SketchPoint


  }

  public void renderDXF(DXFWriter dxf, float offsetX, float offsetY) {

    for (int i = 1; i < this.l.size() + 1; i++) {
      SketchPoint curVec = null;
      SketchPoint preVec = null;

      if (i >= 1)
        preVec = (SketchPoint) this.l.get(i - 1);

      // --- last or first point ---
      if (i == 1) {
        dxf.lineTo(preVec.x + offsetX, preVec.y + offsetY);
      }

      if (i == this.l.size()) {
        curVec = (SketchPoint) this.l.get(0);
      } else {
        curVec = (SketchPoint) this.l.get(i);
      }

      if (curVec.containsBezier() || preVec.containsBezier()) {

        for (float t = 0; t <= 1; t += 0.1f) {
          float x = functions.bezierPoint(preVec.x,
              preVec.getControlPoint2().x,
              curVec.getControlPoint1().x, curVec.x, t);
          float y = functions.bezierPoint(preVec.y,
              preVec.getControlPoint2().y,
              curVec.getControlPoint1().y, curVec.y, t);
          dxf.lineTo(x + offsetX, y + offsetY);
        }

      } else {
View Full Code Here


        }
        */

  public void renderToPlotter(HPGLWriter hpglWriter) {
    for (int i = 1; i < this.l.size() + 1; i++) {
      SketchPoint curVec = null;
      SketchPoint preVec = null;

      // --- last or first point ---
      if (i == 1) {
        curVec = (SketchPoint) this.l.get(0);
        hpglWriter.move(curVec.x, curVec.y);
      }

      if (i >= 1)
        preVec = (SketchPoint) this.l.get(i - 1);

      if (i == this.l.size()) {
        curVec = (SketchPoint) this.l.get(0);
        preVec = (SketchPoint) this.l.get(this.l.size() - 1);

      } else {
        curVec = (SketchPoint) this.l.get(i);
      }

      /*
      if (this.bezierPoints.containsKey(curVec) || preVec != null
          && this.bezierPoints.containsKey(preVec)) {

        spPoint c1 = preVec;
        spPoint c2 = curVec;

        if (c1 == null)
          c1 = new spPoint(0, 0);

        if (preVec != null && this.bezierPoints.containsKey(preVec)) {
          BezierControlNode bc = (BezierControlNode) this.bezierPoints
              .get(preVec);
          c1 = bc.c2;
        }

        if (this.bezierPoints.containsKey(curVec)) {
          BezierControlNode bc = (BezierControlNode) this.bezierPoints
              .get(curVec);
          c2 = bc.c1;
        }

        if (c1 != null && c2 != null && curVec != null)
        //  g.bezierVertex(c1.x, c1.y, c2.x, c2.y, curVec.x, curVec.y);
        hpglWriter.bezier(preVec.x,preVec.y,c1.x, c1.y, c2.x, c2.y, curVec.x, curVec.y);


      }
      */

      if (curVec.containsBezier() || preVec.containsBezier()) {
        hpglWriter.bezier(preVec.x, preVec.y,
            preVec.getControlPoint2().x,
            preVec.getControlPoint2().y,
            curVec.getControlPoint1().x,
            curVec.getControlPoint1().y, curVec.x, curVec.y);

      } else {
        if (false) {
View Full Code Here

  public void addSketchVec2D(float mouseX, float mouseY) {
    for (int i = 0; i < this.getList().size(); i++) {
      SlicePlane curSlice = this.getList().get(i);
      curSlice.getSketch().getCurrentShape()
          .add(new SketchPoint(mouseX, mouseY));
    }
  }
View Full Code Here

    return minZ;
  }

  public SketchPoint getOverSelectPoint(float x, float y) {

    SketchPoint p = null;
    SketchPoint closest = null;
    float dist = -1;

    for (int i = 0; i < this.getList().size(); i++) {
      SlicePlane curPlane = this.getList().get(i);
View Full Code Here

          SlicePlane tempPlane = this.selectedPlanes.get(0);
          ;
          Vec2D tempP = new Vec2D(GLOBAL.uiTools.mouseX,
              GLOBAL.uiTools.mouseY);
          SketchPath tempPath = new SketchPath(tempPlane.getSketch());
          tempPath.add(new SketchPoint(GLOBAL.uiTools
              .getPointOnPlane(tempP, tempPlane.getPlane())));
          tempPath.add(new SketchPoint(GLOBAL.uiTools
              .getPointOnPlane(tempP, tempPlane.getPlane()).add(
                  100, 0)));
          tempPath.setIsContructionLine(true);
          creossSelectionTempOver = new CrossSliceSelection(tempPath,
              tempPath.getParentSketch().getOnSketchPlane(), 0,
View Full Code Here

        // on the other side !

        if (slicePlane.getPlane().classifyPoint(p1) != slicePlane
            .getPlane().classifyPoint(p2)) {
          //we found a intersect
          SketchPoint vec2D1 = null;

          if (i != 0) {
            vec2D1 = (SketchPoint) path.get(i - 1);
          } else {
            vec2D1 = (SketchPoint) path.get(path.size() - 1);
          }

          SketchPoint vec2D2 = null;
          if (i < path.size()) {
            vec2D2 = (SketchPoint) path.get(i);
          } else {
            vec2D2 = (SketchPoint) path.get(0);
          }

          if (vec2D1 == null || vec2D2 == null)
            break;

          if (vec2D1.containsBezier() || vec2D2.containsBezier()) {
            for (float t = 0; t < 1 - GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS; t += GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS) {
              Vec2D bez1 = vec2D1;
              Vec2D bez2 = vec2D2;

              if (vec2D1.controlPoint2 != null) {
View Full Code Here

    Vec3D p1 = null, p2 = null;
    Vec2D p12D = null, p22D = null;

    for (int i = 0; i < spline.getCentrePath().size() - 1; i++) {

      SketchPoint point1 = spline.getCentrePath().get(i);
      SketchPoint point2 = spline.getCentrePath().get(i + 1);

      float step = 1;

      if (point1.containsBezier() || point2.containsBezier())
        step = GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS;

      float offset = 0;

      if (step != 1)
View Full Code Here

   
    float minZ = sign*planesToSlice.getMinZ();
    float maxZ = sign*planesToSlice.getMaxZ();
    //TODO: Adding +1 to width fixes overlapping issue but does not seem right.
    float materialHalfWidth = ((SETTINGS.materialThickness / 2) / SETTINGS.scale);
    sketchPath.add(new SketchPoint(maxZ-materialHalfWidth+penetration,0));
    sketchPath.add(new SketchPoint(minZ+materialHalfWidth-penetration,0));
    sketchPath.add(new SketchPoint(minZ+materialHalfWidth-penetration, pLen-penetration));
    sketchPath.add(new SketchPoint(maxZ-materialHalfWidth+penetration, pLen-penetration));

    slicePlane.getSketch().getSketchShapes().add(sketchPath);
    sketchPath.setClosed(true);
   
   
View Full Code Here

      Vec3D vecDir = new Vec3D(guideSpline.getPerpendicular(i).x,
          guideSpline.getPerpendicular(i).y, 0);

      // do we want to add a strenghtening beam to the leg
      if (crossSliceSelection.tieToLeg) {
        SketchPoint point1 = (SketchPoint) guideSpline.get(0);
        SketchPoint point2 = (SketchPoint) guideSpline.get(1);
        Vec2D dir2D = point1.sub(point2).normalize();
        dir2D.rotate((float) (Math.PI / 2));
        vecPos = new Vec3D(point2.x, point2.y, 0);
        vecDir = new Vec3D(dir2D.x, dir2D.y, 0);
      }

      SlicePlane slicePlane = new SlicePlane(new Plane(vecPos, vecDir));
      slicePlane.setCrossSliceSelection(crossSliceSelection);

      // SketchOutline sktOutline = new SketchOutline();

      List<SketchPoint> topLine = new ArrayList<SketchPoint>();
      List<SketchPoint> bottomLine = new ArrayList<SketchPoint>();

      for (int j = 0; j < planesToSlice.size(); j++) {
        SlicePlane currentPlaneY = planesToSlice.get(j);
        topLine.add(new SketchPoint(currentPlaneY.getPlane().z, 0));
        bottomLine.add(new SketchPoint(currentPlaneY.getPlane().z,
            crossSliceSelection.getSlatHeight()));

        if (j != 0 && j != planesToSlice.size() - 1) {

          SliceSlot slot = new SliceSlot(slicePlane, new Vec2D(
              vecPos.x, vecPos.y), new Vec2D(vecDir.x, vecDir.y),
              (crossSliceSelection.getSlatHeight() / 2),
              SETTINGS.materialThickness);
          //slot.setOnEdge(new Vec2D(0, 1));
          currentPlaneY.getSketch().getSlots().add(slot);

          slot = new SliceSlot(currentPlaneY, new Vec2D(
              currentPlaneY.getPlane().z,
              (crossSliceSelection.getSlatHeight() / 2)),
              new Vec2D(1, 0),
              (crossSliceSelection.getSlatHeight() / 2),
              SETTINGS.materialThickness);
          //slot.setOnEdge(new Vec2D(0,1));
          slicePlane.getSketch().getSlots().add(slot);

        }
      }

      // now go around the lines we collected and add them to a
      // outline
      Vec2D controlPointLeft = null;
      Vec2D bezierPointLeft = null;

      Vec2D controlPointRight = null;
      Vec2D bezierPointRight = null;

      // now change the line caping
      if (bottomLine.size() > 1) {

        controlPointRight = bottomLine.get(0);
        bezierPointRight = bottomLine.get(1);

        controlPointLeft = bottomLine.get(bottomLine.size() - 1);
        bezierPointLeft = bottomLine.get(bottomLine.size() - 2);
        bottomLine.remove(0);
        bottomLine.remove(bottomLine.size() - 1);

        if (crossSliceSelection.tieToLeg) {
          controlPointRight = new Vec2D(bezierPointRight.x - 15,
              bezierPointRight.y);
          controlPointLeft = new Vec2D(bezierPointLeft.x + 15,
              bezierPointLeft.y);

        }
      }

      SketchPath sketchPath = new SketchPath(slicePlane.getSketch());

      for (int i1 = 0; i1 < topLine.size(); i1++) {
        SketchPoint tempP = topLine.get(i1);
        // sktOutline.add(tempVec);
        sketchPath.add(tempP);

        float offsetX = (width / (numSlices - 1)) / 2;

        if (i1 != 0 && i1 != topLine.size() - 1
            && SETTINGS_SKETCH.Draw_Curves)
          sketchPath.addBezier(tempP,
              new Vec2D(tempP.x - offsetX, tempP.y), new Vec2D(
                  tempP.x + offsetX, tempP.y));

      }

      for (int i1 = bottomLine.size() - 1; i1 >= 0; i1--) {
        // sketchPath.add((Vec2D) bottomLine.get(i1));
        SketchPoint tempP = bottomLine.get(i1);
        sketchPath.add(tempP);

        float offsetX = (width / (numSlices - 1)) / 2;

        if (i1 != bottomLine.size() - 1 && i1 != 0
View Full Code Here

          guideSpline.getPerpendicular(i).y, 0);
      vecDir = vecDir.rotateZ(crossSliceSelection.offsetRotation);
      //vecDir = vecDir.rotateZ((float) (Math.PI ));
      // do we want to add a strengthening beam to the leg
      if (crossSliceSelection.tieToLeg) {
        SketchPoint point1 = (SketchPoint) guideSpline.get(0);
        SketchPoint point2 = (SketchPoint) guideSpline.get(1);
        Vec2D dir2D = point1.sub(point2).normalize();
        dir2D.rotate((float) (Math.PI / 2));
        vecPos = new Vec3D(point1.x, point1.y, 0);
        vecDir = new Vec3D(dir2D.x, dir2D.y, 0);
      }

      SlicePlane slicePlane = new SlicePlane(new Plane(vecPos, vecDir));
      slicePlane.setCrossSliceSelection(crossSliceSelection);

      //slicePlane.getPlane().normal.rotateZ((float) -(Math.PI/2));
      SketchPath topLine = new SketchPath(null);
      SketchPath bottomLine = new SketchPath(null);

      topLine.setClosed(false);
      bottomLine.setClosed(false);

      /*
       * Slice up each plane
       *
       * <pre>
       *
       *  1 2 3 4 5 -> (currentPlaneY) go through each plane
       * 
       *  | | | | |
       *  ---------< (crossSliceSelection) calculate intersects
       *  | | | | |
       *  | | | | |
       *  |\ \ \ \ \
       *  | \ \ \ \ \
       *  |  \ \ \ \ \
       *  |  |    |  |
       *     |       |
       *     |       |
       * 
       *  </pre>
       */
      for (int j = 0; j < planesToSlice.size(); j++) {
        SlicePlane currentPlaneY = planesToSlice.get(j);
        // get the spline we want to produce cross sections along
        // do we want to generate planes across the whole profile or
        // just the current sketch?
        //TODO: crop to outline minus leg!
        Object spline = null;
        if (crossSliceSelection.cropToCurrentShape) {
          //if(crossSliceSelection.path instanceof SketchSpline)
          //spline = crossSliceSelection.path;
          spline = currentPlaneY.getSketch().getFirst(); ////THIS IS WRONG TODO:
        } else {

           
          if (currentPlaneY.getSketch().getSketchShapes().sketchOutlines
              .getOutterOutline() == null)
            return;

          spline = currentPlaneY.getSketch().getSketchShapes().sketchOutlines
              .getOutterOutline().getPath();
         
         
         
         

        }

       
       
       
       
        /** GUIDE SKETCHSPLINE
         *  
         * <pre>       
         * intersect points based on center of spline and width
         *           ^
         *      ___|__    __|_____|_____
         *    \/  _|_ \  /  |_____|_____
         *    /\ / |\  \/  /|     |
         *   |  \    \____/   
         *
         * </pre>
         **/
        // we want to produce cross sections just across the current
        // sketch
        if (spline != null && spline instanceof SketchSpline) {
          SketchSpline currentSpline = (SketchSpline) spline;

          //LOGGER.info("slices on SketchSpline");

          if (currentSpline == null) {
            crossSliceSelection.destroy(null);
            return;
          }

          currentSpline = currentSpline;

          Vec2D topIntersect = null;
          Vec2D bottomIntersect = null;

          Vec2D intersectX = new Vec2D(-1, -1);

          Vec2D vecPosOnSpline = currentSpline.getPos(i);
         
          if(vecPosOnSpline != null){
          vecPos = new Vec3D(vecPosOnSpline.x,
              vecPosOnSpline.y,
              currentPlaneY.getPlane().z);

          Vec2D posPerp = currentSpline.getPerpendicular(i);
          float percent = -1f;
          Vec2D percentVec = new Vec2D(-1, -1);

          posPerp = posPerp.rotate(crossSliceSelection.offsetRotation);

          currentPlaneY.getIntersectionCentre(slicePlane,
              currentSpline, i, percentVec, intersectX);
         
         

          if(intersectX.x != -1 && intersectX.y!=-1){
         
         
          float splineWidth = currentSpline.getOffsetSize();
          splineWidth = currentSpline.getOffsetSize(i);

          //  float splineIntersectPercent = percentVec.x;
          //  if (splineIntersectPercent != -1) {

          Vec2D topIntersectY = null;
          Vec2D bottomIntersectY = null;

          float dist = 0;
          float neartestDist = -1;

          Vec2D tempPos = percentVec.copy();// currentSpline.getPos(percentVec.x);
          Vec2D tempDir = posPerp.copy();// currentSpline.getPerpendicular(percentVec.x);

          if (tempDir == null)
            break;

          tempDir = tempDir.normalize();

          topIntersect = intersectX.add(new Vec2D(0, splineWidth));
          bottomIntersect = intersectX.add(new Vec2D(0, -splineWidth));

          // Switch what side slots are added to
          // slots along Y
          Vec2D slotPos = new Vec2D(tempPos.x, tempPos.y);
          Vec2D slotDir = null;
          if (!crossSliceSelection.flipSide) {
            slotDir = new Vec2D(vecDir.x, vecDir.y);
          } else {
            slotDir = new Vec2D(-vecDir.x, -vecDir.y);
          }
          // slotPos.addSelf(slotDir.scale(100));
          float offsetToEdge = -1;
          if (!crossSliceSelection.flipSide) {
            offsetToEdge = 1;
          } else {
            offsetToEdge = -1;
          }

          if (!currentPlaneY.guide) {
            SliceSlot slot = new SliceSlot(slicePlane, slotPos,
                slotDir, (-splineWidth - offsetToEdge),
                SETTINGS.materialThickness);
            slot.swap();
            slot.setOnEdge(new Vec2D(0, 1));
           
if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
  slot.makesEdge = true;

            currentPlaneY.getSketch().getSlots().add(slot);
          }

          if (!currentPlaneY.guide) {
            if (!crossSliceSelection.flipSide) {
              if (j != 0 && j != planesToSlice.size() - 1 ){
                float yPosSlot = intersectX.y + (splineWidth);
                SliceSlot slot = new SliceSlot(
                    currentPlaneY,
                    new Vec2D(intersectX.x,yPosSlot),
                    new Vec2D(-1, 0), splineWidth,
                    SETTINGS.materialThickness);
                if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                  slot.makesEdge = true;
                        slot.setOnEdge(new Vec2D(0,-1)); // these slots start from the middle so this doesn't work, flip slots.

                       
                    //LOGGER.info("X " + slot.getPos().x + " Y " + slot.getPos().y );

                   
                slicePlane
                    .getSketch()
                    .getSlots()
                    .add(slot);
              }
            } else {
              if (j != 0 && j != planesToSlice.size() - 1){

                SliceSlot slot = new SliceSlot(
                    currentPlaneY,
                    new Vec2D(intersectX.x,
                        intersectX.y
                            - (splineWidth)),
                    new Vec2D(1, 0), splineWidth,
                    SETTINGS.materialThickness);
                slot.setOnEdge(new Vec2D(0, -1));
                if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                  slot.makesEdge = true;
                slicePlane
                    .getSketch()
                    .getSlots()
                    .add(slot);
               
              }
            }
          }

          // if(topIntersect != null){

          Vec3D tempVec = new Vec3D(bottomIntersect.x,
              bottomIntersect.y, 0);
          tempVec = slicePlane.getWorldPosIntersect(tempVec);

          if (SETTINGS.DEBUG) {
            currentPlaneY.debugIntersectionPoints.add(slotPos);
            currentPlaneY.debugIntersectionPointsTop.add(tempPos
                .scale(tempDir));
            currentPlaneY.debugIntersectionPointsBottom.add(tempPos
                .scale(tempDir.scale(-1)));
          }


          topLine.add(new SketchPoint(bottomIntersect));
          bottomLine.add(new SketchPoint(topIntersect));
          }
        }
        }

        //}

        /* ACROSS SKETCHPATH */

        /**
         * Find intersections across cross section
         *  
         *   <pre>
         *   currentPath
         *     ^
         *     |
         *    ------   x1 -> (topIntersect)
         *   |       \/ -------------------------> (crossSliceSelection)
         *   |       /\
         *   |      / /
         *    \    /  \
         *      \_/____\
         *       /
         *      x2 -> (bottomIntersect)
         *   </pre>
         */

        else if (spline instanceof SketchPath) {

          SketchPath currentPath = (SketchPath) spline;
         
          vecPos = new Vec3D(vecPos.x, vecPos.y,currentPlaneY.getPlane().z);
         
          //always crop to shape as we work out the correct shape earlier
          List<List<Vec2D>> points = currentPlaneY.getIntersection(
              slicePlane, true,
              currentPath);

          if (points != null && points.size() > 1) {

            Vec2D topIntersect = null;
            Vec2D bottomIntersect = null;
            Vec2D topIntersectY = null;
            Vec2D bottomIntersectY = null;
            Vec2D topIntersectX = null;
            Vec2D bottomIntersectX = null;
            float dist = 0;
            float neartestDist = -1;
            Vec2D vecStart = new Vec2D(vecPos.x, vecPos.y);

            //find the closest point
            for (int k = 0; k < points.size(); k++) {
             
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dX = (Vec2D) points.get(k).get(1);
              Vec3D vec3d = new Vec3D(vec2dX.x, vec2dX.y,vecPos.z);
              float d = vecStart.distanceTo(vec2dX);

              //Display intersects in debug mode
              if (SETTINGS.DEBUG) {
                currentPlaneY.debugIntersectionPoints
                    .add(vec2dX);
                currentPlaneY.debugIntersetStart = new Vec2D(
                    vecPos.x, vecPos.y);
              }

              if (d < neartestDist || neartestDist == -1) {
                neartestDist = d;
                topIntersect = vec2d;
                topIntersectX = vec2dX;
              }

            }

            float MIN_DUPLICATE_DIST = 2;

            //Remove the closest point
            for (int k = 0; k < points.size(); k++) {
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dx = (Vec2D) points.get(k).get(1);

              float distToLastIntersect = topIntersectX
                  .distanceTo(vec2dx);

              if (vec2d.equals(topIntersect)
                  || distToLastIntersect < MIN_DUPLICATE_DIST) {
                points.remove(k);
                k--;
              }

            }

            //find the next closest intersect!
            neartestDist = -1;
            for (int k = 0; k < points.size(); k++) {
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dX = (Vec2D) points.get(k).get(1);

              Vec3D vec3d = new Vec3D(vec2d.x, vec2d.y,
                  currentPlaneY.getPlane().z);
              float d = vecStart.distanceTo(vec2dX);

              if ((d < neartestDist && vec2d != topIntersect)
                  || neartestDist == -1) {

                neartestDist = d;
                bottomIntersect = vec2d;
                bottomIntersectX = vec2dX;
              }
            }

           
            /**
             * Lets Fix any intersects that are swapped around
             */
            if ((bottomIntersect != null && topIntersect != null)
                && bottomIntersect.y < topIntersect.y) {
              Vec2D topIntersectTemp = topIntersect.copy();
              Vec2D topIntersectXTemp = topIntersectX.copy();

              topIntersect = bottomIntersect;
              topIntersectX = bottomIntersectX;

              bottomIntersect = topIntersectTemp;
              bottomIntersectX = topIntersectXTemp;

            }

           
            /**
             * Are slats a set height?
             */
            if (crossSliceSelection.getSlatHeight() != 0) {
              bottomIntersect = topIntersect.add(0,
                  crossSliceSelection.getSlatHeight());
              bottomIntersectX = topIntersectX.add(0,
                  crossSliceSelection.getSlatHeight());
            }

            if (SETTINGS.DEBUG) {
              currentPlaneY.debugIntersectionPointsTop
                  .add(topIntersectX);
              currentPlaneY.debugIntersectionPointsBottom
                  .add(bottomIntersectX);

            }

            //if we have found both intersects then add them to the outline
            if (bottomIntersect != null && topIntersect != null) {
              float len = bottomIntersect
                  .distanceTo(topIntersect);

              if (!currentPlaneY.guide) {

                if (crossSliceSelection.flipSide) {
                  Vec2D slotPos = bottomIntersectX.copy();
                  Vec2D dirPerp = new Vec2D(vecDir.x,
                      vecDir.y);
                  dirPerp.rotate((float) (Math.PI / 2));
                  SliceSlot slot = new SliceSlot(slicePlane,
                      slotPos, new Vec2D(
                          -vecDir.x,
                          -vecDir.y),
                      (len / 2f),
                      SETTINGS.materialThickness);
                  slot.setOnEdge(new Vec2D(0, -1));
                  if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                    slot.makesEdge = true;
                  currentPlaneY
                      .getSketch()
                      .getSlots()
                      .add(slot);

                } else {
                  Vec2D slotPos = topIntersectX.copy();
                  Vec2D dirPerp = new Vec2D(vecDir.x,
                      vecDir.y);
                  dirPerp.rotate((float) (Math.PI / 2));
                  SliceSlot slot = new SliceSlot(slicePlane,
                      slotPos,
                      new Vec2D(vecDir.x,
                          vecDir.y),
                      (len / 2f),
                      SETTINGS.materialThickness);
                  slot.setOnEdge(new Vec2D(0, -1));
                  if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                    slot.makesEdge = true;
                  // Switch what side slots are added to
                  currentPlaneY
                      .getSketch()
                      .getSlots()
                      .add(slot);
                }
              }

              Vec2D topSlotintersect = bottomIntersect.copy();
              Vec2D bottomtopSlotintersect = topIntersect.copy();

              if (!currentPlaneY.guide) {

                if (!crossSliceSelection.flipSide) {
                  if (j != 0
                      && j != planesToSlice.getList()
                          .size() - 1){
                    SliceSlot slot = new SliceSlot(
                        currentPlaneY,
                        topSlotintersect,
                        new Vec2D(-1, 0),
                        (len / 2f),
                        SETTINGS.materialThickness);
                    slot.setOnEdge(new Vec2D(0, -1));
                    if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                      slot.makesEdge = true;
                    slicePlane
                        .getSketch()
                        .getSlots()
                        .add(slot);
                  }
                } else {
                  if (j != 0
                      && j != planesToSlice.getList()
                          .size() - 1){
                    SliceSlot slot = new SliceSlot(
                        currentPlaneY,
                        bottomtopSlotintersect,
                        new Vec2D(1, 0),
                        ((len / 2f)),
                        SETTINGS.materialThickness);
                    slot.setOnEdge(new Vec2D(0, -1));
                    if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                      slot.makesEdge = true;
                    slicePlane
                        .getSketch()
                        .getSlots()
                        .add(slot);
                  }
                }
              }
              // if(topIntersect != null){

              // add bezier points

              /**
               * BUILD the legs
               *
               * ________
               * |:/  \:|
               * ||    ||
               * --    --
               */
             
              if (crossSliceSelection.tieToLeg) {
                // if(crossSliceSelection.tiedToPlanes.contains(currentPlaneY)){
               
               
                if (crossSliceSelection.legSpline != null
                    && crossSliceSelection.legSpline
                        .getPath() != null
                    && crossSliceSelection.tiedToPlanes.contains(currentPlaneY)) {
                 
                 
                 
                 
                 
                  Vec2D seatBottom = null;

                  if(crossSliceSelection.extendLegSliceToTopOfLeg){
                    seatBottom = new Vec2D(0,0);
                  }else{
                 
                   
                    SketchShapes tempSketchShapes = currentPlaneY.getSketch().getSketchShapes().clone();
                   
                    tempSketchShapes.removeLegs();
                    tempSketchShapes.sketchOutlines.clear();
                    tempSketchShapes.buildOutline();
                   
                    if (tempSketchShapes.sketchOutlines
                        .getOutterOutline() == null)
                      return;
                   
                   
                    SketchShape sktch = tempSketchShapes.sketchOutlines.getOutterOutline().getPath();

                   
                    List<List<Vec2D>> points02 = currentPlaneY.getIntersection(
                        slicePlane, true,
                        sktch);
                   
                   
                    for (int k = 0; k < points02.size(); k++) {
                     
                      Vec2D vec2d = (Vec2D) points02.get(k).get(0);
                      if(seatBottom == null || vec2d.distanceTo(topIntersect) > vec2d.distanceTo(seatBottom) )
                        seatBottom = vec2d;
                     
                    }
           
                 
                   if(seatBottom == null)
                    seatBottom = bottomIntersect;
                 
                  }
                  // this is hard coded so legs are always on
                  // the outside slices!
                  topLine.add(new SketchPoint(topIntersect));


                  //bottomLine.add(new SketchPoint(bottomIntersect));
                  float legWidthBottom = 20;
                  float legWidthTop = 20;
                  SketchSpline legSpline = crossSliceSelection.legSpline;
                  float Yoffset = 0;
                  float yMin = 0;
                 
                  SketchPoint p1 = null, p2, p3, p4;
                  if (legSpline.getPath().size() == 4) {
                    p1 = (SketchPoint) legSpline.getPath()
                        .get(1);
                    p2 = (SketchPoint) legSpline.getPath()
                        .get(2);

                    p3 = (SketchPoint) legSpline.getPath()
                        .get(0);
                    p4 = (SketchPoint) legSpline.getPath()
                        .get(3);

                    legWidthBottom = p1.distanceTo(p2);
                    legWidthTop = p3.distanceTo(p4);
                    Yoffset = 0;
                   
                   
                   
                    Vec2D p5 = GLOBAL.uiTools.getPointOnPlane(legSpline.getCentrePath().get(0), slicePlane.getPlane());
                    Vec2D p6 = GLOBAL.uiTools.getPointOnPlane(legSpline.getCentrePath().get(1), slicePlane.getPlane());

                    //slicePlane.getPlane().getIntersectionWithRay(r);
                    yMin = 29;//Math.min(p5.y,p6.y);
                   


                   
                  }
                 
                  //Get the last intersect
                  //TODO this will get the intersect to the left, whitch is not always desirable
                 
                  if(bottomLine.size() > 0)
                    Yoffset = bottomLine.get(bottomLine.size()-1).y;

                  //TODO: LEG STUFF
                  //Yoffset = legSpline.getCentrePath().get(0).distanceTo(legSpline.getCentrePath().get(1));
                  bottomLine.add(new SketchPoint(
                      bottomIntersect.x
                          - (legWidthTop / 2),
                          seatBottom.y));

                  bottomLine.add(new SketchPoint(
                      bottomIntersect.x
                          - (legWidthBottom / 2),
                      bottomIntersect.y));

                //  bottomLine.add(new SketchPoint(
                //      bottomIntersect.x,
                //      yMin));

                  bottomLine.add(new SketchPoint(
                      bottomIntersect.x
                          + (legWidthBottom / 2),
                      bottomIntersect.y));

                  bottomLine.add(new SketchPoint(
                      bottomIntersect.x
                          + (legWidthTop / 2),
                          seatBottom.y));

                } else {

                  topLine.add(new SketchPoint(topIntersect));
                  bottomLine.add(new SketchPoint(
                      bottomIntersect));

                }

              } else {
                topLine.add(new SketchPoint(topIntersect));
                bottomLine
                    .add(new SketchPoint(bottomIntersect));

              }

            }
          }
        }
      }

     
     
      /**
       * Check what direction our slats are going in and reverse them if they're going in the wrong dir
       */
     
      if(topLine.size() > 0 && ((SketchPoint)topLine.get(0)).x > ((SketchPoint)topLine.get(topLine.size()-1)).x){
        topLine.reverseWinding();
        bottomLine.reverseWinding();
      }
     
      /**
       * Should we generate flat tops?
       *
       */

     
      // now go around the lines we collected and add them to a
      // outline
      Vec2D controlPointLeft = null;
      Vec2D bezierPointLeft = null;

      Vec2D controlPointRight = null;
      Vec2D bezierPointRight = null;

      if (crossSliceSelection.smooth) {
        bottomLine.smoothLeft(SETTINGS_SKETCH.SMOOTH_AMOUNT);
        topLine.smoothRight(SETTINGS_SKETCH.SMOOTH_AMOUNT);
      }
     
     
      if(crossSliceSelection.generateFlushTops){
       
        float materialWidth = SETTINGS.materialThickness/SETTINGS.scale; //TODO: change this so it is more general
        for (int i1 = 0; i1 < topLine.size(); i1++) {
          SketchPoint tempP = topLine.get(i1);
         

         
          SketchPoint pLeft = new SketchPoint(tempP.x+((materialWidth/2)), tempP.y);
          SketchPoint pRight = new SketchPoint(tempP.x-((materialWidth/2)), tempP.y);

          if(tempP.containsBezier()){
            //pLeft.controlPoint1 = tempP.controlPoint1.copy();
           
            pLeft.controlPoint2 = tempP.controlPoint2.copy();
            pRight.controlPoint1 = tempP.controlPoint1.copy();
           
            //pRight.controlPoint2 = tempP.controlPoint2.copy();

          }
          topLine.set(i1,pLeft);
          topLine.add(i1, pRight);
          i1++;

        }
       
       
        if(crossSliceSelection.type != CrossSliceSelection.LEG){
         
         
         
          for (int i1 = 0; i1 < bottomLine.size(); i1++) {
            SketchPoint tempP = bottomLine.get(i1);
            SketchPoint pLeft = new SketchPoint(tempP.x-(materialWidth/2), tempP.y);
            SketchPoint pRight = new SketchPoint(tempP.x+(materialWidth/2), tempP.y);

            if(tempP.containsBezier()){
              //pLeft.controlPoint1 = tempP.controlPoint1.copy();
              pLeft.controlPoint2 = tempP.controlPoint2.copy();

              pRight.controlPoint1 = tempP.controlPoint1.copy();
              //pRight.controlPoint2 = tempP.controlPoint2.copy();

            }
            bottomLine.set(i1,pRight);
            bottomLine.add(i1, pLeft);
            i1++;

          }
         
        }
       
       
       
      }
     
     

      /**
       * <pre>
       * CAPPING
       * |-----------|
       * |-----------|
       * </pre>
       */

      SketchPath sketchPath = new SketchPath(slicePlane.getSketch());

      if (crossSliceSelection.getCapType() == CrossSliceSelection.CAP_ROUND_SQUARE) {
        // now change the line caping
        if (bottomLine.size() > 1) {

          float cornerRad = crossSliceSelection.cornerRadius;
          bottomLine.add(0, (SketchPoint) bottomLine.get(0).clone());
          bottomLine.add((SketchPoint) bottomLine.get(
              bottomLine.size() - 1).clone());

          bottomLine.get(0).addSelf(0, -cornerRad);
          bottomLine.get(1).addSelf(cornerRad, 0);
          bottomLine.get(0).controlPoint1 = new Vec2D(
              bottomLine.get(0).x, bottomLine.get(0).y
                  + cornerRad);
          bottomLine.get(0).controlPoint2 = bottomLine.get(0).copy();

          bottomLine.get(bottomLine.size() - 1)
              .addSelf(0, -cornerRad);
          bottomLine.get(bottomLine.size() - 2)
              .addSelf(-cornerRad, 0);
          bottomLine.get(bottomLine.size() - 1).controlPoint2 = new Vec2D(
              bottomLine.get(bottomLine.size() - 1).x,
              bottomLine.get(bottomLine.size() - 1).y + cornerRad);
          bottomLine.get(bottomLine.size() - 1).controlPoint1 = bottomLine
              .get(bottomLine.size() - 1).copy();

          topLine.add(0, (SketchPoint) topLine.get(0).clone());
          topLine.add((SketchPoint) topLine.get(topLine.size() - 1)
              .clone());

          topLine.get(0).addSelf(0, cornerRad);
          topLine.get(1).addSelf(cornerRad, 0);
          topLine.get(0).controlPoint2 = new Vec2D(topLine.get(0).x,
              topLine.get(0).y - cornerRad);
          topLine.get(0).controlPoint1 = topLine.get(0).copy();

          topLine.get(topLine.size() - 1).addSelf(0, cornerRad);
          topLine.get(topLine.size() - 2).addSelf(-cornerRad, 0);
          topLine.get(topLine.size() - 1).controlPoint1 = new Vec2D(
              topLine.get(topLine.size() - 1).x,
              topLine.get(topLine.size() - 1).y - cornerRad);
          topLine.get(topLine.size() - 1).controlPoint2 = topLine
              .get(topLine.size() - 1).copy();

          for (int i1 = 0; i1 < topLine.size(); i1++) {
            SketchPoint tempP = topLine.get(i1);
            sketchPath.add(tempP);
           
          }

          for (int i1 = bottomLine.size() - 1; i1 >= 0; i1--) {
            SketchPoint tempP = bottomLine.get(i1);
            sketchPath.add(tempP);
           
          }

        }
      }

      // adds a curve to the bottom line
      if (crossSliceSelection.getCapType() == CrossSliceSelection.CAP_CURVE) {
        // now change the line capping
        if (bottomLine.size() > 1) {

          controlPointRight = bottomLine.get(0);
          bezierPointRight = bottomLine.get(1);

          controlPointLeft = bottomLine.get(bottomLine.size() - 1);
          bezierPointLeft = bottomLine.get(bottomLine.size() - 2);
          bottomLine.remove(0);
          bottomLine.remove(bottomLine.size() - 1);

          if (crossSliceSelection.tieToLeg) {
            controlPointRight = new Vec2D(bezierPointRight.x - 15,
                bezierPointRight.y);
            controlPointLeft = new Vec2D(bezierPointLeft.x + 15,
                bezierPointLeft.y);

          }
        }

        for (int i1 = 0; i1 < topLine.size(); i1++) {
          SketchPoint tempP = topLine.get(i1);
          sketchPath.add(tempP);

          float offsetX = (width / (numSlices - 1)) / 2;

          if (i1 != 0 && i1 != topLine.size() - 1
              && SETTINGS_SKETCH.Draw_Curves)
            sketchPath.addBezier(tempP,
                new Vec2D(tempP.x - offsetX, tempP.y),
                new Vec2D(tempP.x + offsetX, tempP.y));

        }

        for (int i1 = bottomLine.size() - 1; i1 >= 0; i1--) {
          SketchPoint tempP = bottomLine.get(i1);
          sketchPath.add(tempP);

          float offsetX = (width / (numSlices - 1)) / 2;

          if (i1 != bottomLine.size() - 1 && i1 != 0
              && !crossSliceSelection.tieToLeg
              && SETTINGS_SKETCH.Draw_Curves)
            sketchPath.addBezier(tempP,
                new Vec2D(tempP.x + offsetX, tempP.y),
                new Vec2D(tempP.x - offsetX, tempP.y));

        }

        if (controlPointLeft != null) {
          sketchPath.addBezier((SketchPoint) bezierPointLeft,
              controlPointLeft,
                  bezierPointLeft);
          sketchPath.addBezier((SketchPoint) bezierPointRight,
              bezierPointRight,
                  controlPointRight);

        }

      }

      if (crossSliceSelection.getCapType() == CrossSliceSelection.CAP_BUTT
          || crossSliceSelection.getCapType() == CrossSliceSelection.CAP_INSIDE) {

        bottomLine.get(0).removeBezier();
        bottomLine.get(bottomLine.size() - 1).removeBezier();

        topLine.get(0).removeBezier();
        topLine.get(topLine.size() - 1).removeBezier();

        for (int i1 = 0; i1 < topLine.size(); i1++) {
          SketchPoint tempP = topLine.get(i1);
          sketchPath.add(tempP);

        }
        for (int i1 = bottomLine.size() - 1; i1 >= 0; i1--) {
          SketchPoint tempP = bottomLine.get(i1);
          sketchPath.add(tempP);
        }

      }

View Full Code Here

TOP

Related Classes of cc.sketchchair.sketch.SketchPoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.