Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shape_tool.IsAssembly(label) returns invalid value? #1319

Open
zero-kappa opened this issue May 6, 2024 · 2 comments
Open

shape_tool.IsAssembly(label) returns invalid value? #1319

zero-kappa opened this issue May 6, 2024 · 2 comments
Labels

Comments

@zero-kappa
Copy link

Hello, I am trying to parse a step file hierarchy with XCAFDoc. However, I found that some assemblies are not correctly recognized.
For instance, here below [C-400-Shasi] is an assembly in freeCAD, but not an assembly in my sample code implemented with pythonOCC.
image
image

Here's the sample codes:

  def findComponents(self, label, comps):
      """Discover components from comps (LabelSequence) of an assembly (label).

      Components of an assembly are, by definition, references which refer to
      either a shape or another assembly. Components are essentially 'instances'
      of the referred shape or assembly, and carry a location vector specifing
      the location of the referred shape or assembly.
      """
      logger.debug("")
      logger.debug("Finding components of label entry %s)", label.EntryDumpToString())
      for j in range(comps.Length()):
          logger.debug("loop %i of %i", j+1, comps.Length())
          cLabel = comps.Value(j+1)  # component label <class 'OCC.Core.TDF.TDF_Label'>
          cShape = self.shape_tool.GetShape(cLabel)
          logger.debug("Component number %i", j+1)
          logger.debug("Component entry: %s", cLabel.EntryDumpToString())
          name = self.getName(cLabel)
          logger.debug("Component name: %s", name)
          refLabel = TDF_Label()  # label of referred shape (or assembly)
          isRef = self.shape_tool.GetReferredShape(cLabel, refLabel)
          if isRef:  # I think all components are references, but just in case...
              refShape = self.shape_tool.GetShape(refLabel)
              refLabelEntry = refLabel.EntryDumpToString()
              logger.debug("Entry referred to: %s", refLabelEntry)
              refName = self.getName(refLabel)
              logger.debug("Name of referred item: %s", refName)
              if self.shape_tool.IsSimpleShape(refLabel):
                  logger.debug("Referred item is a Shape")
                  logger.debug("Name of Shape: %s", refName)
                  logger.info("Is compound? %s ", self.shape_tool.IsCompound(refLabel))
                  logger.info("Number of Components %s ", self.shape_tool.NbComponents(refLabel))
                  rComps = TDF_LabelSequence() # Components of Assy
                  subchilds = False
                  isAssy = self.shape_tool.GetComponents(refLabel, rComps, subchilds)
                  logger.debug("Assy name: %s", name)
                  logger.debug("Is Assembly? %s", isAssy)
                  logger.debug("Number of components: %s", rComps.Length())

                  tempAssyLocStack = list(self.assyLocStack)
                  tempAssyLocStack.reverse()

                  for loc in tempAssyLocStack:
                      cShape.Move(loc)

                  color = self.getColor(refShape)
                  self.tree.create_node(name,
                                        self.getNewUID(),
                                        self.assyUidStack[-1],
                                        {'a': False, 'l': None, 'c': color, 's': cShape})
              elif self.shape_tool.IsAssembly(refLabel):
                  logger.debug("Referred item is an Assembly")
                  logger.debug("Name of Assembly: %s", refName)
                  name = self.getName(cLabel)  # Instance name
                  aLoc = TopLoc_Location()
                  # Location vector is carried by component
                  aLoc = self.shape_tool.GetLocation(cLabel)
                  self.assyLocStack.append(aLoc)
                  newAssyUID = self.getNewUID()
                  self.tree.create_node(name,
                                        newAssyUID,
                                        self.assyUidStack[-1],
                                        {'a': True, 'l': aLoc, 'c': None, 's': None})
                  self.assyUidStack.append(newAssyUID)
                  rComps = TDF_LabelSequence() # Components of Assy
                  subchilds = False
                  isAssy = self.shape_tool.GetComponents(refLabel, rComps, subchilds)
                  logger.debug("Assy name: %s", name)
                  logger.debug("Is Assembly? %s", isAssy)
                  logger.debug("Number of components: %s", rComps.Length())
                  if rComps.Length():
                      self.findComponents(refLabel, rComps)
      self.assyUidStack.pop()
      self.assyLocStack.pop()
@tpaviot tpaviot added the STEP label May 13, 2024
@tpaviot
Copy link
Owner

tpaviot commented May 13, 2024

can you please include the test step file

@zero-kappa
Copy link
Author

@tpaviot Sorry for late response. Due to certain constraints, I am unable to provide the STEP file for the original example. However, I have included an another STEP file where the same issue is present:
image
The test step file is included in the following .zip file:
test_step.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants