Revision: 78056
          http://sourceforge.net/p/brlcad/code/78056
Author:   starseeker
Date:     2021-01-08 15:33:50 +0000 (Fri, 08 Jan 2021)
Log Message:
-----------
Checkpoint

Modified Paths:
--------------
    brlcad/trunk/src/libged/npush/npush.cpp

Modified: brlcad/trunk/src/libged/npush/npush.cpp
===================================================================
--- brlcad/trunk/src/libged/npush/npush.cpp     2021-01-07 19:01:18 UTC (rev 
78055)
+++ brlcad/trunk/src/libged/npush/npush.cpp     2021-01-08 15:33:50 UTC (rev 
78056)
@@ -25,8 +25,8 @@
 
 #include "common.h"
 
-#include <stdlib.h>
-#include <string.h>
+#include <set>
+#include <map>
 
 #include "bu/cmd.h"
 #include "bu/opt.h"
@@ -33,6 +33,58 @@
 
 #include "../ged_private.h"
 
+/* When it comes to push operations, the notion of what constitutes a unique
+ * instance is defined as the combination of the object and its associated
+ * parent matrix. Because the dp may be used under multiple matrices, for some
+ * push operations it will be necessary to generate a new unique name to refer
+ * to instances - we store those names with the instances for convenience. */
+class dp_i {
+    public:
+       struct directory *dp;
+       mat_t mat;
+       std::string iname;
+       const struct bn_tol *ts_tol;
+
+       bool operator<(const dp_i &o) const {
+           if (dp < o.dp) return true;
+           if (o.dp < dp) return false;
+           /* If the dp doesn't tell us, check the matrix. */
+           if (!bn_mat_is_equal(mat, o.mat, ts_tol)) {
+               for (int i = 0; i < 16; i++) {
+                   if (mat[i] < o.mat[i]) {
+                       return true;
+                   }
+               }
+           }
+           return false;
+       }
+};
+
+/* Container to hold information during tree walk.  To generate names (or
+ * recognize when a push would create a conflict) we keep track of how many
+ * times we have encountered each dp during processing. */
+struct push_state {
+    std::set<dp_i> s_i;
+    std::map<struct directory *, int> s_c;
+};
+
+
+void comb_cnt(struct db_i *UNUSED(dbip), struct directory *dp, void *data)
+{
+    struct push_state *s = (struct push_state *)data;
+    s->s_c[dp]++;
+    bu_log("Visiting comb: %s (%d)\n", dp->d_namep, s->s_c[dp]);
+}
+
+void solid_cnt(struct db_i *UNUSED(dbip), struct directory *dp, void *data)
+{
+    struct push_state *s = (struct push_state *)data;
+    s->s_c[dp]++;
+    bu_log("Visiting solid: %s (%d)\n", dp->d_namep, s->s_c[dp]);
+}
+
+
+
 static void
 npush_usage(struct bu_vls *str, struct bu_opt_desc *d) {
     char *option_help = bu_opt_describe(d, NULL);
@@ -64,10 +116,13 @@
 
     BU_OPT_NULL(d[7]);
 
+    /* Skip command name */
+    argc--; argv++;
+
     /* parse standard options */
     int opt_ret = bu_opt_parse(NULL, argc, argv, d);
 
-    if (argc == 1 || print_help) {
+    if (!argc || print_help) {
        struct bu_vls npush_help = BU_VLS_INIT_ZERO;
        npush_usage(&npush_help, d);
        bu_vls_sprintf(gedp->ged_result_str, "%s", bu_vls_cstr(&npush_help));
@@ -81,10 +136,19 @@
     GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
     GED_CHECK_READ_ONLY(gedp, GED_ERROR);
     GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
+    struct db_i *dbip = gedp->ged_wdbp->dbip;
 
     /* initialize result */
     bu_vls_trunc(gedp->ged_result_str, 0);
 
+    struct push_state s;
+    for (int i = 0; i < argc; i++) {
+       struct directory *dp = db_lookup(dbip, argv[i], LOOKUP_NOISY);
+       if (dp != RT_DIR_NULL) {
+           db_functree(dbip, dp, comb_cnt, solid_cnt, &rt_uniresource, &s);
+       }
+    }
+
     return GED_OK;
 }
 

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