lost functionality - GeomBSplineSurface::Restore / Save

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

[EDIT] requires Silk addon to follow along

when i load
Silk_Demo_03.FCStd
(452.12 KiB) Downloaded 12 times
the model loads with a clean model tree, but there is some kind of error in the report view > GeomBSplineSurface::Restore
Silk_Demo_03_debug_00.PNG
Silk_Demo_03_debug_00.PNG (365.84 KiB) Viewed 698 times
the three errors correspond to the three "CubicNStarSurface_NStar66" document objects.

if i delete one of these objects, i can remake it from the underlying "ControlGridNStar66_NSub" object
Silk_Demo_03_debug_01.PNG
Silk_Demo_03_debug_01.PNG (329.2 KiB) Viewed 698 times
Silk_Demo_03_debug_02.PNG
Silk_Demo_03_debug_02.PNG (350.93 KiB) Viewed 698 times
this does not trigger any new errors in the report view.

when i save the modified file however, i get a new error
Silk_Demo_03_debug_04.PNG
Silk_Demo_03_debug_04.PNG (348.16 KiB) Viewed 698 times
unlike the three loading errors, i get only one error here, for the re-created surface.
[continued]
Last edited by emills2 on Sun Mar 26, 2023 10:40 pm, edited 1 time in total.
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

when i open the modified file,
Silk_Demo_03_debug_04.FCStd
(467.54 KiB) Downloaded 7 times
i get the previous GeomBSplineSurface::Restore error, as well as a fatal error for the surface i attempted to re-create
Silk_Demo_03_debug_05.PNG
Silk_Demo_03_debug_05.PNG (314.55 KiB) Viewed 667 times
so the "GeomBSplineSurface::Save" error leave the file worse off than i started.

these objects are created and added to the documents as

Code: Select all

from __future__ import division # allows floating point division from integers
import FreeCAD, Part, math
from FreeCAD import Base
from FreeCAD import Gui
import ArachNURBS as AN

# Locate Workbench Directory
import os, Silk_dummy
path_Silk = os.path.dirname(Silk_dummy.__file__)
path_Silk_icons =  os.path.join( path_Silk, 'Resources', 'Icons')

class CubicNStarSurface_NStar66():
	def Activated(self):
		NStar66 = Gui.Selection.getSelection()[0]
		a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","CubicNStarSurface_NStar66")
		AN.CubicNStarSurface_NStar66(a, NStar66)
		a.ViewObject.Proxy=0 # just set it to something different from None (this assignment is needed to run an internal notification)
		a.ViewObject.DisplayMode = u"Shaded"
		a.ViewObject.ShapeColor = (0.33,0.67,1.00)
		FreeCAD.ActiveDocument.recompute()
	
	def GetResources(self):
		return {'Pixmap' :  path_Silk_icons + '/CubicNStarSurface_NStar66.svg', 'MenuText': 'CubicNStarSurface_NStar66', 'ToolTip': 'CubicNStarSurface_NStar66'}

Gui.addCommand('CubicNStarSurface_NStar66', CubicNStarSurface_NStar66())
the above is a generic format for all workbench commands, and the specific function is "AN.CubicNStarSurface_NStar66(a, NStar66)"

which is defined like this

Code: Select all

class CubicNStarSurface_NStar66: 
	def __init__(self, obj , NStarGrid):
		''' Add the properties '''
		FreeCAD.Console.PrintMessage("\nCubicNStarSurface_NStar66 Init\n")
		obj.addProperty("App::PropertyLink","NStarGrid","CubicNStarSurface_NStar66","control grid star").NStarGrid = NStarGrid
		obj.addProperty("Part::PropertyGeometryList","NSurf","CubicNStarSurface_NStar66","N Cubic Surfaces").NSurf
		obj.Proxy = self

	def HomogeneousGrids(self, fp, N):
		HomogeneousGrids = [0] * N
		for i in range(N):
			HGrid_i = [0] *36
			for j in range(36):
				# convert the float list from NStarGrid back to Base.Vector.
				HGrid_i[j] = [Base.Vector(fp.NStarGrid.StarGrid[i][j][0][0],fp.NStarGrid.StarGrid[i][j][0][1],fp.NStarGrid.StarGrid[i][j][0][2]), fp.NStarGrid.StarGrid[i][j][1]] 
			HomogeneousGrids[i] = HGrid_i
		return HomogeneousGrids

	def makeNSurf(self, fp, HomogeneousGrids, N):
		NSurf = [0] * N
		for i in range(N):
			NSurf[i] = NURBS_Cubic_66_surf(HomogeneousGrids[i])
		return NSurf

	def execute(self,fp):
		# cast [x ,y, z] in linked NstarGrid back to Base.Vector
		HomogeneousGrids = self.HomogeneousGrids(fp, fp.NStarGrid.N)

		#loop over the homogeneous grids to make the surfaces
		NSurf = self.makeNSurf(fp, HomogeneousGrids, fp.NStarGrid.N)
		fp.NSurf = NSurf

		fp.Shape = Part.Shape(fp.NSurf)
the key steps here are:
-a python feature object "a" is added to the doc as "CubicNStarSurface_NStar66"
-this object "a" is passed along to the function "AN.CubicNStarSurface_NStar66(a, NStar66)" along with the parameter "NStar66"
-the function "CubicNStarSurface_NStar66" adds two parameters to the object "a": NStarGrid(receives the parameter NStar66), and Nsurf (which will hold the output geometry)
-the input parameter is massaged a bit (float list to Base.Vector, etc)
-NSurf is is set to be a list
-for each item in NSurf, NURBS_Cubic_66_surf() is called, which itself returns a Part.BSplineSurface()
-Nsurf is then assigned to be the Shape of the python feature object.

fp.Shape = Part.Shape(fp.NSurf)
this line is how is basically always handle the assigning of the shape to my workbench objects. all the grids work this way for example: build a list of lines, and assign that list as object.Shape

so the object's Shape points to NSurf, which is a list of Part.BSplineSurface() objects. at this point we have a feature python object with 2 attributes, one that holds the input parameter, and one that holds the results as a list of Part.BSplineSurface() objects.

everything works up to this point. the object is added to the document, and the Shape is rendered correctly.

but then it doesn't save correctly. Upon reopening the file, it appears a geometry section of the xml was never written correctly.

I think something has changed in the rules for saving, but i don't know where to start looking.

Any help understanding the situation and how to fix it would be greatly appreciated. The error seems to be happening at a much deeper level than anything i have ever dealt with directly. the error in the report view is not very decriptive.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by wmayer »

https://github.com/FreeCAD/FreeCAD/blob ... .cpp#L4544

Save & Restore is not yet implemented for any surface geometry types.
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

wmayer wrote: Sun Mar 26, 2023 10:44 pm https://github.com/FreeCAD/FreeCAD/blob ... .cpp#L4544

Save & Restore is not yet implemented for any surface geometry types.
thanks for the fast reply Werner. I'm very confused, so i must be misunderstanding you. it worked for years, in the sense that this model below has 99 saved versions???
Silk_model_99_03.png
Silk_model_99_03.png (195.83 KiB) Viewed 652 times
i created the objects, they were added to the document, they displayed, they saved, they opened correctly...there is no way that i manually recreated all these objects in each file. it's not even possible because the dependency goes sketch>poly>grid>surface>grid>grid>surface....you can't just save the file without the surfaces, reopen and recreate the surfaces "real quick". the surfaces are embedded throughout.

i have models with several hundred saved versions? And they actually open and render correctly (with error messages). the only real trouble starts when trying to work further on them now.
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

wmayer wrote: Sun Mar 26, 2023 10:44 pm https://github.com/FreeCAD/FreeCAD/blob ... .cpp#L4544

Save & Restore is not yet implemented for any surface geometry types.
Is this "Save & Restore" something new in the last few years, which wasn't needed before? and somehow before it just worked?
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

emills2 wrote: Sun Mar 26, 2023 11:01 pm
wmayer wrote: Sun Mar 26, 2023 10:44 pm https://github.com/FreeCAD/FreeCAD/blob ... .cpp#L4544

Save & Restore is not yet implemented for any surface geometry types.
Is this "Save & Restore" something new in the last few years, which wasn't needed before? and somehow before it just worked?
like maybe before it just recomputed every time instead of saving the surface? is there a way i can prevent the saving of surfaces? that way it just recomputes? that is very possibly what was happening before. that would be fine really.
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

i mean, obviously it would be very nice to save all surface geometry data, although an option to not do so would still be nice (for smaller files on disk)

but since right now we can't, a smaller file with a longer load time due to recompute would be better than a broken file.
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

if instead of deleting/recreating one of the complex 'multi-patch' objects, i just redo a single surface, everything works.
Silk_Demo_03_debug_06.PNG
Silk_Demo_03_debug_06.PNG (301.27 KiB) Viewed 602 times
shown above:
-a blue surface deleted
-redone in pink
-saved with no issues

now we reopen the modified file
Silk_Demo_03_debug_05.FCStd
(440.9 KiB) Downloaded 5 times
Silk_Demo_03_debug_07.PNG
Silk_Demo_03_debug_07.PNG (363.47 KiB) Viewed 602 times
-the file reopens.
-the errors from opening the original file are gone!!!
-the new pink surface is fine
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

so this seems to only affect the case where the shape is a list of surfaces, but if only a single Part.BSplineSurface() is assigned, there is no visible issue.
emills2
Posts: 868
Joined: Tue Apr 28, 2015 11:23 pm

Re: lost functionality - GeomBSplineSurface::Restore / Save

Post by emills2 »

this model
Silk_model_151_test_0.18_py3.FCStd
(822.41 KiB) Downloaded 7 times
had no 'multi-surface' objects in it. meaning each document object has at most one Part.BSplineSurface() in its Shape. it loads correctly (some warnings)

i edited the very first sketch in the dependency hierarchy. it updated correctly. 'save as' gave no errors
Silk_model_161_test_0.21_00.PNG
Silk_model_161_test_0.21_00.PNG (289.11 KiB) Viewed 523 times
reopening the document gives no errors
Silk_model_161_test_0.21.FCStd
(814.58 KiB) Downloaded 8 times
Silk_model_161_test_0.21_01.PNG
Silk_model_161_test_0.21_01.PNG (274.51 KiB) Viewed 523 times
these files aren't perfect by any means. sketcher behavior is slightly different then before, and previously good sketches are sometimes overconstrained. i'm not worried about that, and i don't mind reviewing the sketches and fixing them.

the point of interest here is that the only difference between these files and the problem file is that i have objects whose shape is a list of Part.BSplineSurface(), instead of a single Part.BSplineSurface(). the only diffrence i can identify anyways.
Post Reply