Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #***************************************************************************
- #* Copyright (c) 2013
- #* Daniel Falck <ddfalck@gmail.com>
- #*
- #* This program is free software; you can redistribute it and/or modify
- #* it under the terms of the GNU Lesser General Public License (LGPL)
- #* as published by the Free Software Foundation; either version 2 of
- #* the License, or (at your option) any later version.
- #* for detail see the LICENCE text file.
- #*
- #* This program is distributed in the hope that it will be useful,
- #* but WITHOUT ANY WARRANTY; without even the implied warranty of
- #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- #* GNU Library General Public License for more details.
- #*
- #* You should have received a copy of the GNU Library General Public
- #* License along with this program; if not, write to the Free Software
- #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- #* USA
- #***************************************************************************
- from FreeCADGui import Selection
- from FreeCAD import Base
- from PyQt4 import QtCore
- import DraftGeomUtils
- def cornerTrim(line1,line2,nearpoint1,nearpoint2):
- '''extends a Draft Line to another line -very similar to extend command in AutoCAD and it's clones '''
- edge1=line1.Object.Shape.Edges[0]
- edge2=line2.Object.Shape.Edges[0]
- #boundary =edge1,line to extend = edge2,nearpoint catches nearest vertex on line to extend
- #find the intersection point first
- intpt = DraftGeomUtils.findIntersection(edge1,edge2,True,True)
- #find index of closest end point of line to extend
- closestpointindex1 = DraftGeomUtils.findClosest(nearpoint1,line1.Object.Points)
- #extend the line from the closest point
- if closestpointindex1==0:
- line1.Object.Start = ( intpt[0].x,intpt[0].y,intpt[0].z)
- else:
- line1.Object.End = ( intpt[0].x,intpt[0].y,intpt[0].z)
- closestpointindex2 = DraftGeomUtils.findClosest(nearpoint2,line2.Object.Points)
- #extend the line from the closest point
- if closestpointindex2==0:
- line2.Object.Start = ( intpt[0].x,intpt[0].y,intpt[0].z)
- else:
- line2.Object.End = ( intpt[0].x,intpt[0].y,intpt[0].z)
- #selection stuff
- class SelObserver:
- selected=False
- def addSelection(self, doc, object, sub, point):
- self.selected=True
- self.point=point
- def QtWait(ms):
- "QtWait(ms) Wait some time, leaving QT do its job."
- timer=QtCore.QTimer()
- timer.setSingleShot(True)
- loop=QtCore.QEventLoop()
- QtCore.QObject.connect(timer,QtCore.SIGNAL("timeout()"),loop,QtCore.SLOT("quit()"))
- timer.start(ms)
- loop.exec_(QtCore.QEventLoop.AllEvents)
- def wait4sel(gate):
- "wait4sel('gate') Wait for a selection filtered by the gate and return the clicked point"
- so=SelObserver()
- if (gate !=""):
- Selection.addSelectionGate(gate)
- Selection.addObserver(so)
- while (not so.selected):
- QtWait(100)
- Selection.removeSelectionGate()
- Selection.removeObserver(so)
- return so.point
- Msg("Select boundary Edges\r\n")
- pt=wait4sel("SELECT Part::Feature SUBELEMENT Edge")
- theObject=Selection.getSelectionEx()[0]
- Msg("Select line to extend\r\n")
- pt2=wait4sel("SELECT Part::Feature SUBELEMENT Edge")
- theObject2=Selection.getSelectionEx()[0]
- cornerTrim(theObject,theObject2,Base.Vector(pt),Base.Vector(pt2))
- App.activeDocument().recompute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement