Nurbs editor

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Nurbs editor

Post by microelly2 »

triplus wrote: P.S. Looking forward to test the BSpline editor!
here the prototype https://youtu.be/CmhZlU1V46Y
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

Looking good.

Note that i don't plan to work further on this for now. But i decided to try out if i can get a working prototype to move a representation of the interpolated point of the BSpline on the screen and for the BSpline to update accordingly after. And doing that by using your spreadsheet prototype macro as a base for it:

Code: Select all

# version 0.1

from PySide import QtGui
from PySide import QtCore

import FreeCAD,Draft
import  nurbswb.needle
from nurbswb.needle import npa2ssa,ssa2npa

draftPts = []

def updateSS(ss,curve):
   '''update curve data into spreadsheet'''
   ss.clearAll()
   npa2ssa(curve,ss,2,3,(1.0,1.0,0.5))
   ss.set('B1',str(len(curve)))
   App.activeDocument().recompute()


def updateDraft(ss,obj):
   '''update Draft Bspline object points from spreadsheet ss'''
   global points
   cl=int(ss.get('B1'))
   curve=ssa2npa(ss,2,3,4,3+cl-1)
   obj.Points=[FreeCAD.Vector(c) for c in curve]
   points = obj.Points

global writeBack,ss,obj2,points

def writeBack():
   global ss
   global obj2
   updateDraft(ss,obj2)
   App.activeDocument().recompute()
   Gui.SendMsgToActiveView("ViewFit")

def onApply():
    writeBack()
    for i in draftPts:
        App.activeDocument().removeObject(i.Name)
    del draftPts[:]
    for i in points:
        point = Draft.makePoint(i + obj2.Placement.Base)
        draftPts.append(point)

def onUpdate():
    pts = []
    for i in draftPts:
        pts.append(i.Shape.Point)
    updateSS(ss, pts)
    onApply()

btnApply = QtGui.QPushButton("Apply")
btnApply.clicked.connect(onApply)
btnUpdate = QtGui.QPushButton("Update")
btnUpdate.clicked.connect(onUpdate)

def pressed(index):
   pass

def clicked():
   pass

def undock(ss):
   ''' open the data spreadsheet as top level window'''

   label=ss.Label
   mw=FreeCADGui.getMainWindow()
   mdiarea=mw.findChild(QtGui.QMdiArea)

   ss.ViewObject.startEditing(0)
   subw=mdiarea.subWindowList()

   for i in subw:
      if i.widget().metaObject().className() == "SpreadsheetGui::SheetView":
         sheet = i.widget()
         table=sheet.findChild(QtGui.QTableView)
         print "table found"
         break

#   table.clicked.connect(clicked)
   table.pressed.connect(pressed)

   sws=mdiarea.subWindowList()
   print "windows ..."
   for w2 in sws:
      print str(w2.windowTitle())
      if str(w2.windowTitle()).startswith(label):
         sw=w2
         print "found"
         bl=w2.children()[3]
         blcc=bl.children()[2].children()

         w=QtGui.QWidget()
         w.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
         buttons = QtGui.QHBoxLayout()
         buttons.addStretch(0)
         buttons.addWidget(btnUpdate)
         buttons.addWidget(btnApply)

         box = QtGui.QVBoxLayout()
         w.setLayout(box)
         ss=blcc[3]
         box.addWidget(ss)
         box.insertLayout(1, buttons)
         w.setGeometry(50, 30, 650, 350)
         w.show()
         sw.close()
         return w



# test  case

#create the Bspline
p1 = FreeCAD.Vector(0,0,0)
p2 = FreeCAD.Vector(1,1,0)
p3 = FreeCAD.Vector(0,2,0)
p4 = FreeCAD.Vector(-1,1,0)
Draft.makeBSpline([p1,p2,p3,p4],closed=True)

# extract the data
obj=App.ActiveDocument.ActiveObject
bc=obj.Shape.Edge1.Curve
poles=bc.getPoles()
knots=bc.getKnots()
we=bc.getWeights()
mults=bc.getMultiplicities()

pts=obj.Points


poles
knots
we
mults


# create a d fill the spreadsheet
ss = App.activeDocument().addObject('Spreadsheet::Sheet','Spreadsheet')
updateSS(ss,pts)


# create an other Draft BSpline
p1 = FreeCAD.Vector(0,0,0)
p2 = FreeCAD.Vector(10,1,0)
p3 = FreeCAD.Vector(0,2,0)
Draft.makeBSpline([p1,p2,p3],closed=True)
obj2=App.ActiveDocument.ActiveObject
Gui.SendMsgToActiveView("ViewFit")

# write Points back
updateDraft(ss,obj2)

# open Spreadsheet
w=undock(ss)

onApply()
Run the macro and after use the Draft Move on BSpline or change some values in the spreadsheet and press Apply button to see points re-created. Or use Draft Move on one of the points and after press on Update button to see spreadsheet and BSpline updated. Note that as for the translations of BSpline i didn't investigate further on how to take care of the rotations and things like that. Creating version with QTimer is just adding few more lines. I didn't publish that as after closing the dialog i would need to take care of removing the timer and things like that first. Not hard to do but out of scope for now from my side.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

I had an extra hour of free time today and decided to test the theory out:

Image

viewtopic.php?f=24&t=19772#p152640
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Nurbs editor

Post by microelly2 »

I have added some more comfort to the editor and learned more about QTableWidget Events.

https://youtu.be/VyTWMJ5dtpg

It can now be used for Wires and Beziers too.
And I see the possibility to use the Widget for VectorList Properties like Animation Tracks.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

Yep this is it.

The level of (engineering) control i do feel comfortable working with on a curve level. This is something i can start using in production environment and get results. Anyway looking back i got the tool i felt suits my needs. And now i guess i will leave you to others and your own visions for a while to progress this and other areas further! And i get to use (and test) the tool should the need arise. ;)
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

@microelly2

I remembered how we where discussing on how to use PieMenu for Nurbs editor purposes. Curve editor clearly shows how that can be achieved. If you would in addition make a few standalone commands on the toolbar like:
  • Edit curve (exposes selected curve points)
  • Toggle poles/knot curve points
  • Move curve point command (select base point and point on a curve)
Such commands can easily be added to PieMenu and the interaction becomes really fast. And as a bonus at the same time current FreeCAD UX interaction paradigm is preserved as the solution doesn't have to be tailored just for PieMenu.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Nurbs editor

Post by microelly2 »

triplus wrote:@microelly2

I remembered how we where discussing on how to use PieMenu for Nurbs editor purposes. Curve editor clearly shows how that can be achieved. If you would in addition make a few standalone commands on the toolbar like:
  • Edit curve (exposes selected curve points)
  • Toggle poles/knot curve points
  • Move curve point command (select base point and point on a curve)
Such commands can easily be added to PieMenu and the interaction becomes really fast. And as a bonus at the same time current FreeCAD UX interaction paradigm is preserved as the solution doesn't have to be tailored just for PieMenu.
Yes, its not forgotten - I have alredy the "move commands" x y z t n d r as candidates and the workflow then can be pie menu -> direction select -> mouse move for distance and click to commit.
But for the next weeks I need most time to support our CAM project which uses the geodata nurbs to get a terrain model: https://www.youtube.com/watch?v=ajbFLpeI7vk
Konstantin
Posts: 261
Joined: Wed Jul 23, 2014 10:10 am

Re: Nurbs editor

Post by Konstantin »

Hello. It's all impressive, but where can I get this NURBS editor to play with it? I'm lost in this thread and all of it's links :)

And a litle/huge feature request for the future. (Or, maybe explain to me why nobody does it)
I want not NURBS surface, which approximates surface somewhere inbetween control points, I want surface to go strictly thru control points.

Is it so useless, or is it so hard to implement, so nobody does it?
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Nurbs editor

Post by microelly2 »

Konstantin wrote:Hello. It's all impressive, but where can I get this NURBS editor to play with it? I'm lost in this thread and all of it's links :)
https://github.com/microelly2/freecad-nurbs

And a litle/huge feature request for the future. (Or, maybe explain to me why nobody does it)
I want not NURBS surface, which approximates surface somewhere inbetween control points, I want surface to go strictly thru control points.

Is it so useless, or is it so hard to implement, so nobody does it?
It is possible to approximate or interpolate data but the result is not unique
http://freecadbuch.de/doku.php?id=blog: ... roximieren

interpolation of points to a curve is done by the Draft Bspline Method
interpolation of points to a face:
viewtopic.php?f=13&t=15988&start=10
and geodat workbench https://github.com/microelly2/geodata

and there are methods in reverse engeneering wb.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Import 3DM files with OpenNurbs

Post by keithsloan52 »

microelly2 wrote:
Konstantin wrote:Hello. It's all impressive, but where can I get this NURBS editor to play with it? I'm lost in this thread and all of it's links :)
https://github.com/microelly2/freecad-nurbs
Which reminds me I must get back to development of Importing Rhino 3DM files. Been 3 months since last commit :-(

https://github.com/KeithSloan/FreeCAD_ImportNurbs
Post Reply