Skip to content

Commit

Permalink
environment fixes anticipating #22
Browse files Browse the repository at this point in the history
  • Loading branch information
fstwn committed Jul 6, 2020
1 parent f72133b commit c4db564
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 31 deletions.
5 changes: 2 additions & 3 deletions modules/Cockatoo/Autoknit/FileIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# RHINO IMPORTS ----------------------------------------------------------------
from Rhino.Geometry import Mesh as RhinoMesh
from Rhino.Geometry import Point3f as RhinoPoint3f
import scriptcontext

# LOCAL MODULE IMPORTS ---------------------------------------------------------
from . import Structs
Expand Down Expand Up @@ -153,7 +152,7 @@ def LoadObj(filepath):
# read from the file in text mode
with open(filepath, "rt") as f:
while True:
scriptcontext.escape_test()
#scriptcontext.escape_test()

# read a line and split it into parts
line = f.readline()
Expand Down Expand Up @@ -211,7 +210,7 @@ def SaveObj(filepath, mesh):
temp = deque()
faces = deque()
while len(fids) > 0:
scriptcontext.escape_test()
#scriptcontext.escape_test()
# if face is complete, check if it is a triangle, append and reset temp
if temp and len(temp) == 4:
if temp[-2] == temp[-1]:
Expand Down
2 changes: 2 additions & 0 deletions modules/Cockatoo/Autoknit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from __future__ import absolute_import

# LOCAL MODULE IMPORTS ---------------------------------------------------------
import Cockatoo.Environment

from . import Engine
from . import FileIO
from . import Structs
Expand Down
50 changes: 50 additions & 0 deletions modules/Cockatoo/Environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# PYTHON STANDARD LIBRARY IMPORTS ----------------------------------------------
from __future__ import absolute_import
from __future__ import print_function

# LOCAL MODULE IMPORTS ---------------------------------------------------------
from . import Exceptions

# CHECKING FOR RHINO DEPENDENCY AND ENVIRONMENT --------------------------------
try:
import Rhino
ISRHINOINSIDE = False
except ImportError:
try:
import rhinoinside
rhinoinside.load()
import Rhino
ISRHINOINSIDE = True
except:
raise Exceptions.RhinoNotPresentError()

def IsRhinoInside():
"""
Check if Rhino is running using rhinoinside.
"""
return ISRHINOINSIDE == True

# CHECKING FOR NETWORKX DEPENDENCY AND VERSION ---------------------------------
try:
import networkx
NXVERSION = networkx.__version__
if not NXVERSION == "1.5":
raise Exceptions.NetworkXVersionError()
except ImportError:
raise Exceptions.NetworkXNotPresentError()

def NetworkXVersion():
"""
Return the version of the used networkx module.
"""
return NXVERSION

# ALL DICTIONARY ---------------------------------------------------------------
__all__ = [
"IsRhinoInside",
"NetworkXVersion"
]

# MAIN -------------------------------------------------------------------------
if __name__ == '__main__':
pass
21 changes: 12 additions & 9 deletions modules/Cockatoo/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@
class CockatooException(Exception):
"""Base class for exceptions in Cockatoo."""

class CockatooImportException(ImportError):
"""Base class for import errors in Cockatoo."""

# DEPENDENCY EXCEPTIONS --------------------------------------------------------

class RhinoNotPresentError(CockatooException):
class RhinoNotPresentError(CockatooImportException):
"""Exception raised when import of Rhino fails."""

class KangarooNotPresentError(CockatooException):
class KangarooNotPresentError(CockatooImportException):
"""Exception raised when import of Kangaroo fails."""

class PlanktonNotPresentError(CockatooException):
class PlanktonNotPresentError(CockatooImportException):
"""Exception raised when import of Plankton fails."""

class NetworkXNotPresentError(CockatooImportException):
"""Exception raised when import of NetworkX fails."""

class NetworkXVersionError(CockatooImportException):
"""Exception raised when NetworkX version is not 1.5."""

# KNITNETWORK EXCEPTIONS -------------------------------------------------------

class KnitNetworkError(CockatooException):
"""Exception for a serious error in a KnitNetwork of Cockatoo."""

class NetworkXNotPresentError(KnitNetworkError):
"""Exception raised when import of NetworkX fails."""

class NetworkXVersionError(KnitNetworkError):
"""Exception raised when NetworkX version is not 1.5."""

class KnitNetworkGeometryError(KnitNetworkError):
"""Exception raised when vital geometry operations fail."""

Expand Down
43 changes: 31 additions & 12 deletions modules/Cockatoo/KnitNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@
import math
from operator import itemgetter

# RHINO IMPORTS ----------------------------------------------------------------
from Rhino.Geometry import Curve as RhinoCurve
from Rhino.Geometry import Line as RhinoLine
from Rhino.Geometry import Interval as RhinoInterval
from Rhino.Geometry import Vector3d as RhinoVector3d

# THIRD PARTY MODULE IMPORTS ---------------------------------------------------
import networkx as nx

# LOCAL MODULE IMPORTS ---------------------------------------------------------
from .Environment import IsRhinoInside
from .Exceptions import *
from .KnitNetworkBase import KnitNetworkBase
from .KnitMappingNetwork import KnitMappingNetwork

import ahd
# RHINO IMPORTS ----------------------------------------------------------------
if IsRhinoInside():
import rhinoinside
rhinoinside.load()
from Rhino.Geometry import Curve as RhinoCurve
from Rhino.Geometry import Line as RhinoLine
from Rhino.Geometry import Interval as RhinoInterval
from Rhino.Geometry import Vector3d as RhinoVector3d
else:
from Rhino.Geometry import Curve as RhinoCurve
from Rhino.Geometry import Line as RhinoLine
from Rhino.Geometry import Interval as RhinoInterval
from Rhino.Geometry import Vector3d as RhinoVector3d

# ALL DICTIONARY ---------------------------------------------------------------
__all__ = [
Expand Down Expand Up @@ -1078,7 +1085,7 @@ def AllNodesBySegment(self, data=False, edges=False):

allSegments = mapnet.SegmentContourEdges
allSegmentNodes = [(n, d) for n, d \
in self.nodes_iter(data=True) if d["segment"]]
in self.nodes_iter(data=True) if d["segment"]]

segdict = {}
for n in allSegmentNodes:
Expand All @@ -1091,22 +1098,34 @@ def AllNodesBySegment(self, data=False, edges=False):
if data and edges:
for segment in allSegments:
segval = segment[2]["segment"]
segnodes = sorted(segdict[segval])
try:
segnodes = sorted(segdict[segval])
except KeyError:
segnodes = []
anbs.append((segval, segnodes, segment))
elif data and not edges:
for segment in allSegments:
segval = segment[2]["segment"]
segnodes = sorted(segdict[segval])
try:
segnodes = sorted(segdict[segval])
except KeyError:
segnodes = []
anbs.append((segval, segnodes))
elif not data and edges:
for segment in allSegments:
segval = segment[2]["segment"]
segnodes = sorted(segdict[segval])
try:
segnodes = sorted(segdict[segval])
except KeyError:
segnodes = []
anbs.append((segval, [sn[0] for sn in segnodes], segment))
elif not data and not edges:
for segment in allSegments:
segval = segment[2]["segment"]
segnodes = sorted(segdict[segval])
try:
segnodes = sorted(segdict[segval])
except KeyError:
segnodes = []
anbs.append((segval, [sn[0] for sn in segnodes]))

return anbs
Expand Down
21 changes: 15 additions & 6 deletions modules/Cockatoo/KnitNetworkBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
from __future__ import print_function
from collections import OrderedDict

# RHINO IMPORTS ----------------------------------------------------------------
from Rhino.Geometry import Curve as RhinoCurve
from Rhino.Geometry import Line as RhinoLine
from Rhino.Geometry import LineCurve as RhinoLineCurve
from Rhino.Geometry import Polyline as RhinoPolyline

# THIRD PARTY MODULE IMPORTS ---------------------------------------------------
import networkx as nx

# LOCAL MODULE IMPORTS ---------------------------------------------------------
from .Environment import IsRhinoInside
from .Exceptions import KnitNetworkGeometryError

# RHINO IMPORTS ----------------------------------------------------------------
if IsRhinoInside():
import rhinoinside
rhinoinside.load()
from Rhino.Geometry import Curve as RhinoCurve
from Rhino.Geometry import Line as RhinoLine
from Rhino.Geometry import LineCurve as RhinoLineCurve
from Rhino.Geometry import Polyline as RhinoPolyline
else:
from Rhino.Geometry import Curve as RhinoCurve
from Rhino.Geometry import Line as RhinoLine
from Rhino.Geometry import LineCurve as RhinoLineCurve
from Rhino.Geometry import Polyline as RhinoPolyline

# ALL DICTIONARY ---------------------------------------------------------------
__all__ = [
"KnitNetworkBase"
Expand Down
4 changes: 3 additions & 1 deletion modules/Cockatoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# LOCAL MODULE IMPORTS ---------------------------------------------------------
from . import Autoknit
from . import Environment
from . import Exceptions
from .KnitNetworkBase import KnitNetworkBase
from .KnitNetwork import KnitNetwork
Expand All @@ -11,10 +12,11 @@
# ALL DICTIONARY ---------------------------------------------------------------
__all__ = [
"Autoknit",
"Environment",
"Exceptions",
"KnitNetworkBase",
"KnitNetwork",
"KnitMappingNetwork"
"KnitMappingNetwork",
]

# MAIN -------------------------------------------------------------------------
Expand Down

0 comments on commit c4db564

Please sign in to comment.