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!
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

microelly2 wrote:Have you tested this my script?
Yes i copy/pasted the one you published. The new one looks better:
Compare.png
Compare.png (5.16 KiB) Viewed 2354 times
where does this error raise?
Again i just copy/pasted the macro you published and followed the instructions:
Clicking into the first column should open a dialog to write the data back
After clicking on the Save button i get the error (function updateDraft). Don't worry about it too much. If you ever plan to provide a proper command that does something like that it can be ironed out then.
Yes, when we can modify single surfaces in a acceptabel manner then moving, connecting of multiple surfaces should be the next.
Good to hear that.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Nurbs editor

Post by microelly2 »

triplus wrote:
After clicking on the Save button i get the error (function updateDraft). Don't worry about it too much. If you ever plan to provide a proper command that does something like that it can be ironed out then.
Do you use the old version of FreeCAD: FreeCAD.Vector in this case still does not accept items of a numpy array.

The next steps:
Starting from a needle segments can be extracted and post processed
So we can "pad" faces to volumes

demo segmentation:
https://www.youtube.com/watch?v=1bae-shMFe4
example of a paded faces
Image
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

microelly2 wrote:Do you use the old version of FreeCAD: FreeCAD.Vector in this case still does not accept items of a numpy array.
Yes that was it. I only tested on FreeCAD 0.16.
Connected.png
Connected.png (10.22 KiB) Viewed 2315 times
A lot of things can still be improved but i am comfortable in having such control. The only problem is the result as i was expecting something else to be seen on the screen! I researched a bit and it looks like Periodic BSpline is what i am after. I searched for "Periodic BSpline FreeCAD" and found there is an issue report available already for this:

http://www.freecadweb.org/tracker/view.php?id=358
shoogen - 2013-10-23 08:09

Though the flag is called closed in FreeCAD it means periodic.
//! If PeriodicFlag is true, the constrained BSpline

//! curve will be periodic and closed. In this case,

//! the junction point is the first point of the table Points.

how ever the resulting curve is not periodic.
That i guess confirms Close flag set to True for Draft BSpline doesn't produce Periodic BSpline. Werner provided some workarounds there but i haven't study them yet. As something like this is what i would expect to get as a result instead:
fig10-11.jpg
fig10-11.jpg (46.01 KiB) Viewed 2315 times
http://www.globalspec.com/reference/610 ... ine-curves
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Nurbs editor

Post by microelly2 »

We can achieve it with Part.BSplineCurve(), so DraftBspline can be fixed too.
bp_322.png
bp_322.png (73.35 KiB) Viewed 2287 times
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

microelly2 wrote:We can achieve it with Part.BSplineCurve(), so DraftBspline can be fixed too.
By using the trick Werner used in the issue report or this "just works" for Part.BSplineCurve()? As from regular FreeCAD user point of view anything beyond setting the closed flag to true is i guess not all that manageable. Sure it can work but the reality from regular FreeCAD user point of view is it just doesn't work. And if you take feature requests (sure i could help but too much FreeCAD projects already going on i have to finish myself):
  • Instead of clicking in A column add Apply/Close buttons at the bottom of the QWidget dialog by using some layouts. As there is no need to have 3 pop-up windows/dialogs opened to Apply/Save the change.
  • After you could move the coordinates to A column.
  • Add this tool to your WB as a standard command button on a toolbar with the icon and all the bells and whistles involved.
  • Add two buttons (or one toggle button) to the dialog and when clicked Draft/Part points are created (or removed) to visualise interpolated points on the curve.
  • When Apply button is clicked points are automatically re-created.
  • When Close button in clicked points are automatically removed.
I don't feel i suggested anything you couldn't add with ease and in straightforward fashion. And after this is done i guess we can discuss this further. ;)

P.S. If you for whatever reason don't want to go down this road just ignore the suggestions.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Nurbs editor

Post by microelly2 »

Yes, now I will add a simplified version of the spreadsheet with some buttons for the update logic as a command to my wb.
In this case I do not need an extra Spreadsheet::Sheet but only a QtGui.TableWidget.

Then all other can work as you explained.
Never stop learning.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

microelly2 wrote:Yes, now I will add a simplified version of the spreadsheet with some buttons for the update logic as a command to my wb.
In this case I do not need an extra Spreadsheet::Sheet but only a QtGui.TableWidget.

Then all other can work as you explained.
Never stop learning.
Sounds good.

As for using QTableWidget instead. I guess all of this is still in rough prototype state. Therefore maybe for now using spreadsheet makes more sense compared to moving to QTableWidget. As you save time and who knows maybe other ideas can be tested when using the spreadsheet. Once everything will be figured out things can be explored further on what makes more sense.

And to add to the rough prototype nature. You could use QTimer when the dialog would be opened and it would do an interval check of the position of points. If the point position change would be detected (users used Draft Modify tool or changed the position property) BSpline/spreadsheet would be updated accordingly.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

I added the Apply button and decided to share the result as it makes testing easier. As for the Close button. The macro is in too rough state ATM to care about the Close button. As it wouldn't do the correct thing anyway.
Apply.png
Apply.png (28.9 KiB) Viewed 2232 times

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

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'''
   cl=int(ss.get('B1'))
   curve=ssa2npa(ss,2,3,4,3+cl-1)
   obj.Points=[FreeCAD.Vector(c) for c in curve]

global writeBack,ss,obj2

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

btnApply = QtGui.QPushButton("Apply")
btnApply.clicked.connect(writeBack)

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(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)
Last edited by triplus on Mon Jan 09, 2017 7:39 pm, edited 1 time in total.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Nurbs editor

Post by microelly2 »

Thank you,I have played with the table widget
bp_323.png
bp_323.png (24.17 KiB) Viewed 2230 times
I will write the methods for both.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Nurbs editor

Post by triplus »

If you already started the work on QTableWidget based dialog i feel you should finish the work and build on that. As likely that will result in end solution perceived as "more proper" anyway. Compared to extracting Spreadsheet from MDI view as it is done now. Spreadsheet has the ability to for example make 2 points of different BSplines equal (only temporarily for the macro above but still). That is basically the only thing i was after to preserve for tests in this prototype phase. But as you already went ahead focus on that and forget about the rest for now.

P.S. Looking forward to test the BSpline editor!
Post Reply