Revision: 75373
          http://sourceforge.net/p/brlcad/code/75373
Author:   starseeker
Date:     2020-04-13 13:27:10 +0000 (Mon, 13 Apr 2020)
Log Message:
-----------
Cherrypick r75056 - Add .r suffixes to regions in 3dm-g import

Modified Paths:
--------------
    brlcad/branches/RELEASE/NEWS
    brlcad/branches/RELEASE/src/libgcv/plugins/rhino/rhino_read.cpp

Property Changed:
----------------
    brlcad/branches/RELEASE/
    brlcad/branches/RELEASE/NEWS

Index: brlcad/branches/RELEASE
===================================================================
--- brlcad/branches/RELEASE     2020-04-13 13:08:06 UTC (rev 75372)
+++ brlcad/branches/RELEASE     2020-04-13 13:27:10 UTC (rev 75373)

Property changes on: brlcad/branches/RELEASE
___________________________________________________________________
Modified: svn:mergeinfo
## -6,4 +6,4 ##
 /brlcad/branches/opencl:65867-66137
 /brlcad/branches/osg:62110-62113
 /brlcad/branches/prep-cache:68236-68933
-/brlcad/trunk:36844-37285,37571-38764,38777-38845,41559-43155,43159-43908,44241-44324,44326-44385,44710-45373,45377,45379-47342,47370-68122,68125-74976,75325
\ No newline at end of property
+/brlcad/trunk:36844-37285,37571-38764,38777-38845,41559-43155,43159-43908,44241-44324,44326-44385,44710-45373,45377,45379-47342,47370-68122,68125-74976,75056,75325
\ No newline at end of property
Modified: brlcad/branches/RELEASE/NEWS
===================================================================
--- brlcad/branches/RELEASE/NEWS        2020-04-13 13:08:06 UTC (rev 75372)
+++ brlcad/branches/RELEASE/NEWS        2020-04-13 13:27:10 UTC (rev 75373)
@@ -14,6 +14,7 @@
 ----------------------------------------------------------------------
 
 * fixed solid editing in MGED (reverts transparency change) Cliff Yapp
+* added .r suffixes to region names in 3dm-g conversion - Cliff Yapp
 
 
 ----------------------------------------------------------------------


Property changes on: brlcad/branches/RELEASE/NEWS
___________________________________________________________________
Modified: svn:mergeinfo
## -7,4 +7,4 ##
 /brlcad/branches/osg/NEWS:62110-62113
 /brlcad/branches/prep-cache/NEWS:68236-68933
 /brlcad/trunk:68170-68252
-/brlcad/trunk/NEWS:36844-37285,37571-38764,38777-38845,41559-43155,43159-43908,44241-44324,44326-44385,44710-45373,45377,45379-47342,47370-68122,68125-74373,74376-74976
\ No newline at end of property
+/brlcad/trunk/NEWS:36844-37285,37571-38764,38777-38845,41559-43155,43159-43908,44241-44324,44326-44385,44710-45373,45377,45379-47342,47370-68122,68125-74373,74376-74976,75056
\ No newline at end of property
Modified: brlcad/branches/RELEASE/src/libgcv/plugins/rhino/rhino_read.cpp
===================================================================
--- brlcad/branches/RELEASE/src/libgcv/plugins/rhino/rhino_read.cpp     
2020-04-13 13:08:06 UTC (rev 75372)
+++ brlcad/branches/RELEASE/src/libgcv/plugins/rhino/rhino_read.cpp     
2020-04-13 13:27:10 UTC (rev 75373)
@@ -124,7 +124,42 @@
        bu_bomb("db_lookup() failed");
 }
 
+static void
+comb_region_name_check(std::map<const directory *, std::string> &renamed, db_i 
&db, const std::string &name)
+{
+    RT_CK_DBI(&db);
+    // If name doesn't have a .r suffix, add it
+    struct bu_vls ext = BU_VLS_INIT_ZERO;
+    bool add_ext = false;
+    if (bu_path_component(&ext, name.c_str(), BU_PATH_EXT)) {
+       if (!BU_STR_EQUAL(bu_vls_cstr(&ext), ".r")) {
+           // Have an ext, but not the right one - add .r
+           add_ext = true;
+       }
+    } else {
+       // Don't have an ext - add it
+       add_ext = true;
+    }
+    bu_vls_free(&ext);
 
+    if (!add_ext) {
+       return;
+    }
+
+    struct bu_vls nname = BU_VLS_INIT_ZERO;
+    bu_vls_sprintf(&nname, "%s.r", name.c_str());
+
+    directory * const dir = db_lookup(&db, name.c_str(), true);
+    if (dir == RT_DIR_NULL) {
+       return;
+    }
+    std::pair<const directory *, std::string> rpair = std::make_pair(dir, 
name);
+    if (db_rename(&db, dir, bu_vls_cstr(&nname))){
+       return;
+    }
+    renamed.insert(rpair);
+}
+
 struct UuidCompare {
     bool operator()(const ON_UUID &left, const ON_UUID &right) const
     {
@@ -699,6 +734,7 @@
 HIDDEN void
 polish_output(const gcv_opts &gcv_options, db_i &db)
 {
+    std::map<const directory *, std::string> renamed;
     bu_ptbl found = BU_PTBL_INIT_ZERO;
     AutoPtr<bu_ptbl, db_search_free> autofree_found(&found);
 
@@ -715,17 +751,25 @@
     db_search_free(&found);
     BU_PTBL_INIT(&found);
 
-    if (0 > db_search(&found, DB_SEARCH_RETURN_UNIQ_DP,
-                     "-type comb -attr rgb -not -above -attr rgb -or -attr 
shader -not -above -attr shader",
-                     0, NULL, &db, NULL))
+    // Set region flags, add .r suffix to regions if not already present
+    renamed.clear();
+    const char *reg_search = "-type comb -attr rgb -not -above -attr rgb -or 
-attr shader -not -above -attr shader";
+    if (0 > db_search(&found, DB_SEARCH_RETURN_UNIQ_DP, reg_search, 0, NULL, 
&db, NULL))
        bu_bomb("db_search() failed");
+    bu_ptbl found_instances = BU_PTBL_INIT_ZERO;
+    AutoPtr<bu_ptbl, db_search_free> 
autofree_found_instances(&found_instances);
+    if (0 > db_search(&found_instances, DB_SEARCH_TREE, reg_search, 0, NULL, 
&db, NULL))
+       bu_bomb("db_search() failed");
 
     if (BU_PTBL_LEN(&found)) {
        directory **entry;
 
        for (BU_PTBL_FOR(entry, (directory **), &found)) {
+
            comb_to_region(db, (*entry)->d_namep);
 
+           comb_region_name_check(renamed, db, (*entry)->d_namep);
+
            if (gcv_options.randomize_colors) {
                // random colors mode: TODO: move this into a filter after 
7.26.0
                std::string rgb;
@@ -742,11 +786,29 @@
        }
     }
 
+    // Update any combs that referred to old region names to reference the new 
ones instead
+    if (BU_PTBL_LEN(&found_instances)) {
+       db_full_path **entry;
+       for (BU_PTBL_FOR(entry, (db_full_path **), &found_instances)) {
+           struct directory *ec = DB_FULL_PATH_CUR_DIR(*entry);
+           struct directory *ep = (*entry)->fp_names[(*entry)->fp_len - 2];
+           std::map<const directory *, std::string>::iterator rentry = 
renamed.find(ec);
+           if (rentry == renamed.end()) {
+               continue;
+           }
+           bu_ptbl stack = BU_PTBL_INIT_ZERO;
+           AutoPtr<bu_ptbl, bu_ptbl_free> autofree_stack(&stack);
+           if (!db_comb_mvall(ep, &db, rentry->second.c_str(), ec->d_namep, 
&stack))
+               bu_bomb("db_comb_mvall() failed");
+       }
+    }
+    db_search_free(&found_instances);
+
     // rename shapes after their parent layers
     db_search_free(&found);
     BU_PTBL_INIT(&found);
-    std::map<const directory *, std::string> renamed;
 
+    renamed.clear();
     if (0 > db_search(&found, DB_SEARCH_TREE, "-type shape", 0, NULL, &db, 
NULL))
        bu_bomb("db_search() failed");
 

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