Revision: 62237
          http://sourceforge.net/p/brlcad/code/62237
Author:   starseeker
Date:     2014-08-19 15:18:42 +0000 (Tue, 19 Aug 2014)
Log Message:
-----------
Re-enable the hierarchy-first approach.  The difficulty was with 
LocalUnits::length, which is used for scaling in the hierarchy matrix build - 
the hierarchy logic was relying on the brep loop(s) to set the length and 
assuming that the local length is uniform for all objects.  This behavior is 
restored and hierarchy-first conversion now appears to be working, but we 
should look into doing a units lookup on a per-object basis during the 
hierarchy build so we can handle more complex situtations.

Modified Paths:
--------------
    brlcad/trunk/src/conv/step/STEPWrapper.cpp

Modified: brlcad/trunk/src/conv/step/STEPWrapper.cpp
===================================================================
--- brlcad/trunk/src/conv/step/STEPWrapper.cpp  2014-08-19 15:13:52 UTC (rev 
62236)
+++ brlcad/trunk/src/conv/step/STEPWrapper.cpp  2014-08-19 15:18:42 UTC (rev 
62237)
@@ -117,6 +117,7 @@
     MAP_OF_PRODUCT_NAME_TO_ENTITY_ID name2id_map;
     MAP_OF_ENTITY_ID_TO_PRODUCT_NAME id2name_map;
     MAP_OF_ENTITY_ID_TO_PRODUCT_ID id2productid_map;
+    MAP_OF_ENTITY_ID_TO_PRODUCT_ID process_map;
 
     if (!dot_g) {
        return false;
@@ -158,20 +159,12 @@
                        id2name_map[product_id] = pname;
                    }
                    id2productid_map[aBrep->GetId()] = product_id;
+                   /* This length is used in the hierarchy build - this is how
+                    * it was getting set when the Brep build came before the
+                    * hierarch build, so leave it for now, but should there be
+                    * a look-up in the hiearchy build instead of here?*/
+                   LocalUnits::length = aBrep->GetLengthConversionFactor();
 
-                   if (Verbose()) {
-                       if (!pname.empty() && (pname.compare("''") != 0)) {
-                           std::cerr << std::endl << "     Generating Product 
- " << pname ;
-                       } else {
-                           std::cerr << std::endl << "     Generating Product";
-                       }
-                   }
-
-                   if (convert_WriteBrep(aBrep, dot_g, &pname, &name)) {
-                       delete sdr;
-                       bu_exit(1, "ERROR: failure creating advanced boundary 
representation from %s\n", stepfile.c_str());
-                   }
-
                } else { // must be an assembly
                    if (pname.empty() || (pname.compare("''") == 0)) {
                        std::string str = "Assembly@";
@@ -245,19 +238,12 @@
                                id2name_map[aBrep->GetId()] = pname;
                            }
                            id2productid_map[brep_id] = product_id;
+                           /* This length is used in the hierarchy build - 
this is how
+                            * it was getting set when the Brep build came 
before the
+                            * hierarch build, so leave it for now, but should 
there be
+                            * a look-up in the hiearchy build instead of 
here?*/
+                           LocalUnits::length = 
aBrep->GetLengthConversionFactor();
 
-                           if (Verbose()) {
-                               if (!pname.empty() && (pname.compare("''") != 
0)) {
-                                   std::cerr << std::endl << "     Generating 
Product - " << pname ;
-                               } else {
-                                   std::cerr << std::endl << "     Generating 
Product";
-                               }
-                           }
-
-                           if (convert_WriteBrep(aBrep, dotg, &pname, &name)) {
-                               bu_exit(1, "ERROR: failure creating advanced 
boundary representation from %s\n", stepfile.c_str());
-                           }
-
                            if (product_id != brep_id) {
                                mat_t mat;
 
@@ -362,7 +348,6 @@
 
                        bn_mat_mul(mat, toinv_mat, from_mat);
                    }
-
                    dotg->AddMember(comb,member,mat);
                }
                Factory::DeleteObjects();
@@ -373,6 +358,96 @@
        std::cerr << "Error writing BRL-CAD hierarchy." << std::endl;
     }
 
+    for (int i = 0; i < num_ents; i++) {
+       SDAI_Application_instance *sse = instance_list->GetSTEPentity(i);
+       if (sse == NULL) {
+           continue;
+       }
+       std::string name = sse->EntityName();
+       std::transform(name.begin(), name.end(), name.begin(), 
(int(*)(int))std::tolower);
+
+       /* Shape Definition Representation */
+       if ((sse->STEPfile_id > 0) && 
(sse->IsA(SCHEMA_NAMESPACE::e_shape_definition_representation))) {
+           ShapeDefinitionRepresentation *sdr = 
dynamic_cast<ShapeDefinitionRepresentation *>(Factory::CreateObject(this, 
(SDAI_Application_instance *)sse));
+           if (!sdr) {
+               bu_exit(1, "ERROR: unable to allocate a 
'ShapeDefinitionRepresentation' entity\n");
+           } else {
+               std::string pname  = sdr->GetProductName();
+               pname = dotg->CleanBRLCADName(pname);
+
+               AdvancedBrepShapeRepresentation *aBrep = 
sdr->GetAdvancedBrepShapeRepresentation();
+               if (aBrep) {
+
+                   if (Verbose()) {
+                       if (!pname.empty() && (pname.compare("''") != 0)) {
+                           std::cerr << std::endl << "     Generating Product 
- " << pname ;
+                       } else {
+                           std::cerr << std::endl << "     Generating Product";
+                       }
+                   }
+
+                   LocalUnits::length = aBrep->GetLengthConversionFactor();
+                   if (convert_WriteBrep(aBrep, dot_g, &pname, &name)) {
+                       delete sdr;
+                       bu_exit(1, "ERROR: failure creating advanced boundary 
representation from %s\n", stepfile.c_str());
+                   }
+
+               }
+               Factory::DeleteObjects();
+           }
+       }
+    }
+    for (int i = 0; i < num_ents; i++) {
+       /* Shape Representation Relationship */
+       SDAI_Application_instance *sse = instance_list->GetSTEPentity(i);
+       if (sse == NULL) {
+           continue;
+       }
+       std::string name = sse->EntityName();
+       std::transform(name.begin(), name.end(), name.begin(), 
(int(*)(int))std::tolower);
+
+
+       if ((sse->STEPfile_id > 0) && 
(sse->IsA(SCHEMA_NAMESPACE::e_shape_representation_relationship))) {
+           ShapeRepresentationRelationship *srr = 
dynamic_cast<ShapeRepresentationRelationship *>(Factory::CreateObject(this, 
(SDAI_Application_instance *)sse));
+           if (srr) {
+               ShapeRepresentation *aSR = dynamic_cast<ShapeRepresentation 
*>(srr->GetRepresentationRelationshipRep_1());
+               AdvancedBrepShapeRepresentation *aBrep = 
dynamic_cast<AdvancedBrepShapeRepresentation 
*>(srr->GetRepresentationRelationshipRep_2());
+               if (!aBrep) { //try rep_1
+                   aBrep = dynamic_cast<AdvancedBrepShapeRepresentation 
*>(srr->GetRepresentationRelationshipRep_1());
+                   aSR = dynamic_cast<ShapeRepresentation 
*>(srr->GetRepresentationRelationshipRep_2());
+               }
+               if ((aSR) && (aBrep)) {
+                   int sr_id = aSR->GetId();
+                   MAP_OF_ENTITY_ID_TO_PRODUCT_ID::iterator it = 
id2productid_map.find(sr_id);
+                   if (it != id2productid_map.end()) { // product found
+                       int product_id = (*it).second;
+                       int brep_id = aBrep->GetId();
+
+                       it = process_map.find(brep_id);
+                       if (it == process_map.end()) { // brep not loaded yet 
so lets do that here.
+                           string pname = id2name_map[brep_id];
+                           if (Verbose()) {
+                               if (!pname.empty() && (pname.compare("''") != 
0)) {
+                                   std::cerr << std::endl << "     Generating 
Product - " << pname ;
+                               } else {
+                                   std::cerr << std::endl << "     Generating 
Product";
+                               }
+                           }
+
+                           LocalUnits::length = 
aBrep->GetLengthConversionFactor();
+                           if (convert_WriteBrep(aBrep, dotg, &pname, &name)) {
+                               bu_exit(1, "ERROR: failure creating advanced 
boundary representation from %s\n", stepfile.c_str());
+                           } else {
+                               process_map[brep_id] = product_id;
+                           }
+                       }
+                   }/**/
+               }
+               Factory::DeleteObjects();
+           }
+       }
+    }
+
     return true;
 }
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to