Commit cdbbd95e authored by Milan Jaros's avatar Milan Jaros
Browse files

new version

parent 6a925ba3
......@@ -632,7 +632,14 @@ static void covise_remove_materials_from_object(Object *ob, Mesh *me)
*/
void CoviseMeshImporter::assign_material_to_geom(Object *ob, Material *ma)
{
BKE_object_material_assign(m_bmain, ob, ma, 1, BKE_MAT_ASSIGN_OBJECT);
if (ma == NULL)
return;
BKE_object_material_assign(m_bmain, ob, ma, 1, BKE_MAT_ASSIGN_OBJECT);
if (ma && ma->id.us > 0) {
//id_us_min(&ma->id); // is already 1 here, but will be set later in BKE_mesh_assign_object
}
//// do we know this material?
//if (uid_material_map.find(ma_uid) == uid_material_map.end()) {
......@@ -775,9 +782,9 @@ Collection* CoviseMeshImporter::find_collection_by_name(const char *collection_n
void CoviseMeshImporter::create_new_colletion_timestep(int timestemp) {
char name[1024];
sprintf(name, "%s_%03d", m_rendererData->collection_name, timestemp);
m_collection_current = BKE_collection_add(m_bmain, m_collection_root, name);
DEG_id_tag_update(&m_collection_current->id, ID_RECALC_COPY_ON_WRITE);
BKE_layer_collection_sync(scene, view_layer);
m_collection_current = BKE_collection_add(m_bmain, m_collection_root, name);
covise_update_collection(m_collection_current, m_bmain, m_context);
covise_layer_collection_sync(scene, view_layer);
}
void CoviseMeshImporter::create_new_collection_and_activate(const char *object_name) {
......@@ -813,14 +820,19 @@ void CoviseMeshImporter::create_new_collection_and_activate(const char *object_n
// delete exist collection
if (collection_check != NULL) {
//comment for macos
//BKE_collection_delete(m_bmain, collection_check, true);
//comment for macos
// BKE_collection_delete(m_bmain, collection_check, true);
// covise_update_collection(collection_check, m_bmain, m_context);
// covise_layer_collection_sync(scene, view_layer);
//BKE_id_multi_tagged_delete(m_bmain);
//covise_id_multi_tagged_delete(m_bmain, m_context);
}
// add new collection
m_collection_current = BKE_collection_add(m_bmain, collection_master, m_rendererData->collection_name);
DEG_id_tag_update(&m_collection_current->id, ID_RECALC_COPY_ON_WRITE);
BKE_layer_collection_sync(scene, view_layer);
covise_update_collection(m_collection_current, m_bmain, m_context);
covise_layer_collection_sync(scene, view_layer);
m_collection_root = m_collection_current;
//BKE_layer_collection_sync(scene, view_layer);
......@@ -1418,7 +1430,8 @@ Object *CoviseMeshImporter::create_mesh_object(std::string geom_uid, int colorpa
//id_us_plus(&old_mesh->id); /* Because BKE_mesh_assign_object would have already decreased it... */
//BKE_id_free_us(m_bmain, old_mesh);
if (material_default == NULL) {
if (material_default == NULL)
{
if (colorpacking == INV_RGBA_IDX) {
material_default = create_colorramp(geom_uid);
}
......@@ -1456,8 +1469,11 @@ Object *CoviseMeshImporter::create_mesh_object(std::string geom_uid, int colorpa
Material* CoviseMeshImporter::create_material(std::string str_mat_id)
{
Material *ma = BKE_material_add(m_bmain, (char *)str_mat_id.c_str());
ma->use_nodes = true;
Material *ma = BKE_material_add(m_bmain, (char *)str_mat_id.c_str());
// if (ma && ma->id.us > 0)
// id_us_min(&ma->id); // is already 1 here, but will be set later in BKE_mesh_assign_object
ma->use_nodes = true;
covise_update_material(m_context, ma);
return ma;
......@@ -1466,7 +1482,10 @@ Material* CoviseMeshImporter::create_material(std::string str_mat_id)
Material* CoviseMeshImporter::create_texture(std::string str_tex_id, Image *img)
{
Material *ma = BKE_material_add(m_bmain, (char *)str_tex_id.c_str());
ma->use_nodes = true;
// if (ma && ma->id.us > 0)
// id_us_min(&ma->id); // is already 1 here, but will be set later in BKE_mesh_assign_object
ma->use_nodes = true;
covise_update_texture(m_context, ma, img);
return ma;
......@@ -1475,8 +1494,12 @@ Material* CoviseMeshImporter::create_texture(std::string str_tex_id, Image *img)
Material* CoviseMeshImporter::create_colorramp(std::string str_mat_id)
{
Material *ma = BKE_material_add(m_bmain, (char *)str_mat_id.c_str());
// if (ma && ma->id.us > 0)
// id_us_min(&ma->id); // is already 1 here, but will be set later in BKE_mesh_assign_object
ma->use_nodes = true;
covise_update_colorramp(m_context, ma, 0);
//covise_update_material(m_context, ma);
covise_update_colorramp(m_context, ma, 0);
return ma;
}
......@@ -1917,6 +1940,11 @@ void ObjectManager::update_scene()
covise_update_scene(CTX_data_scene(m_context), CTX_data_main(m_context), m_context);
}
void ObjectManager::clear_material()
{
m_coviseMeshImporter->clear_material();
}
void ObjectManager::set_params(NodeCoviseBlenderRendererData *ncdsd) {
m_coviseMeshImporter->set_params(ncdsd);
}
......@@ -3177,6 +3205,11 @@ void BlenderRenderer::update_scene()
om->update_scene();
}
void BlenderRenderer::clear_material()
{
om->clear_material();
}
bool BlenderRenderer::is_init() {
return om != NULL;
}
......
......@@ -219,6 +219,8 @@ public:
~CoviseMeshImporter() {}
public:
void clear_material(){ material_default=NULL; }
bool is_time_steps();
bool is_particles();
bool is_volume();
......@@ -450,6 +452,7 @@ public:
////////////////////////
void update_scene();
void clear_material();
void create_new_collection_and_activate(const char *object_name);
void set_params(NodeCoviseBlenderRendererData *ncdsd);
......@@ -477,6 +480,7 @@ public:
void init(bContext *C);
void update_scene();
void clear_material();
bool is_init();
......
......@@ -438,9 +438,38 @@ void covise_update_scene(Scene *sce, Main *bmain, bContext *context)
//WM_event_add_notifier(context, NC_OBJECT | ND_TRANSFORM, NULL);
WM_event_add_notifier(context, NC_SCENE | ND_LAYER, sce);
//WM_event_add_notifier(context, NC_SCENE | ND_SHADING, sce);
//WM_event_add_notifier(context, NC_SCENE | ND_OB_ACTIVE, sce);
WM_event_add_notifier(context, NC_SCENE | ND_LAYER_CONTENT, sce);
WM_event_add_notifier(context, NC_NODE | NA_SELECTED, NULL);
//covise_update_shading_only();
}
void covise_update_collection(Collection* collection, Main* bmain, bContext* context)
{
DEG_id_tag_update(&collection->id, ID_RECALC_COPY_ON_WRITE);
DEG_relations_tag_update(bmain);
WM_event_add_notifier(context, NC_GROUP | ND_LAYER, NULL);
}
void covise_layer_collection_sync(Scene* scene, ViewLayer* view_layer)
{
BKE_layer_collection_sync(scene, view_layer);
DEG_id_tag_update(&scene->id, ID_RECALC_BASE_FLAGS);
WM_main_add_notifier(NC_SCENE | ND_LAYER_CONTENT, NULL);
}
void covise_id_multi_tagged_delete(Main* bmain, bContext* context)
{
BKE_id_multi_tagged_delete(bmain);
/* Force full redraw, mandatory to avoid crashes when running this from UI... */
DEG_relations_tag_update(bmain);
WM_event_add_notifier(context, NC_ID | NA_EDITED, NULL);
WM_event_add_notifier(context, NC_SPACE | ND_SPACE_OUTLINER, NULL);
WM_main_add_notifier(NC_WINDOW, NULL);
}
void covise_update_scene_only(Scene *sce, bContext *context)
......@@ -448,6 +477,12 @@ void covise_update_scene_only(Scene *sce, bContext *context)
WM_event_add_notifier(context, NC_SCENE | ND_LAYER, sce);
}
void covise_update_shading_only()
{
WM_main_add_notifier(NC_MATERIAL | ND_SHADING, NULL);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING_LINKS, NULL);
}
void covise_update_node(bContext *context)
{
WM_event_add_notifier(context, NC_NODE | NA_SELECTED, NULL);
......
......@@ -45,6 +45,10 @@ typedef std::set<Object *> BCObjectSet;
extern void covise_update_scene(CoviseBlenderContext &blender_context, float ctime);
extern void covise_update_scene(Scene *sce, Main *bmain, bContext *context);
extern void covise_update_shading_only();
extern void covise_id_multi_tagged_delete(Main* bmain, bContext* context);
extern void covise_update_collection(Collection* collection, Main* bmain, bContext* context);
extern void covise_layer_collection_sync(Scene* scene, ViewLayer* view_layer);
extern void covise_update_scene_only(Scene *sce, bContext *context);
extern void covise_update_node(bContext *context);
extern void covise_update_material(bContext *context, Material *ma);
......
......@@ -293,7 +293,24 @@ class NODE_OT_tree_path_parent(Operator):
space.path.pop()
return {'FINISHED'}
class NODE_OT_exec_node_tree2(Operator):
'''NODE_OT_exec_node_tree2'''
bl_idname = "node.exec_node_tree2"
bl_label = "Exec Node Tree"
bl_options = {'REGISTER'}
@classmethod
def poll(cls, context):
return (context.space_data.type == 'NODE_EDITOR' and
context.space_data.tree_type == 'CoviseNodeTree')
def execute(self, context):
bpy.ops.node.exec_node_tree()
bpy.ops.outliner.orphans_purge(0)
return {'FINISHED'}
classes = (
NodeSetting,
......@@ -303,4 +320,6 @@ classes = (
NODE_OT_add_search,
NODE_OT_collapse_hide_unused_toggle,
NODE_OT_tree_path_parent,
NODE_OT_exec_node_tree2,
)
......@@ -156,6 +156,7 @@ class NODE_HT_header(Header):
NODE_MT_editor_menus.draw_collapsible(context, layout)
layout.operator("node.exec_node_tree", text="Execute")
#layout.operator("outliner.orphans_purge", text="Purge")
#layout.prop(snode, "auto_execute")
layout.separator_spacer()
......
......@@ -477,13 +477,13 @@ covise_node_categories = [
# Covise Nodes
CoviseNodeCategory("COVISE_INPUT", "Input", items=[
NodeItem("CoviseNodeReadEnsight"),
#NodeItem("CoviseNodeReadANSYS"),
NodeItem("CoviseNodeReadANSYS"),
#NodeItem("CoviseNodeReadASCII"),
#NodeItem("CoviseNodeReadDyna3D"),
#NodeItem("CoviseNodeReadFoam"),
#NodeItem("CoviseNodeReadObj"),
#NodeItem("CoviseNodeReadPLY"),
#NodeItem("CoviseNodeReadStl"),
NodeItem("CoviseNodeReadFoam"),
NodeItem("CoviseNodeReadObj"),
NodeItem("CoviseNodeReadPLY"),
NodeItem("CoviseNodeReadStl"),
#NodeItem("CoviseNodeReadVTK"),
#NodeItem("CoviseNodeRWCovise"),
#NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
......@@ -492,15 +492,15 @@ covise_node_categories = [
#NodeItem("CoviseNodeDomainSurface"),
NodeItem("CoviseNodeCollect"),
NodeItem("CoviseNodeColors"),
#NodeItem("CoviseNodeCutGeometry"),
NodeItem("CoviseNodeCutGeometry"),
NodeItem("CoviseNodeCuttingSurface"),
#NodeItem("CoviseNodeCellToVert"),
NodeItem("CoviseNodeCellToVert"),
NodeItem("CoviseNodeTracer"),
#NodeItem("CoviseNodeVectorScal"),
#NodeItem("CoviseNodeIsoSurface"),
#NodeItem("CoviseNodeIsoLines"),
NodeItem("CoviseNodeVectorScal"),
NodeItem("CoviseNodeIsoSurface"),
NodeItem("CoviseNodeIsoLines"),
#NodeItem("CoviseNodeMakePlots"),
#NodeItem("CoviseNodeMinMax"),
NodeItem("CoviseNodeMinMax"),
#NodeItem("CoviseNodeSelectUsg"),
#NodeItem("CoviseNodePartSelect"),
#NodeItem("CoviseNodeVectorField"),
......
......@@ -634,8 +634,53 @@ static int exec_node_tree_exec(bContext *C, wmOperator *op)
if (ntree->type != NTREE_COVISE)
return OPERATOR_FINISHED;
/////////////////////////////////////////////////
//Main* bmain = CTX_data_main(C);
//ScrArea* area = CTX_wm_area(C);
//SpaceOutliner* soops = CTX_wm_space_outliner(C);
//int num_tagged[INDEX_ID_MAX] = { 0 };
//if ((num_tagged[INDEX_ID_NULL] = RNA_int_get(op->ptr, "num_deleted")) == 0) {
// /* Tag all IDs having zero users. */
// ID* id;
// FOREACH_MAIN_ID_BEGIN(bmain, id) {
// outliner_orphans_purge_tag(id, num_tagged);
// }
// FOREACH_MAIN_ID_END;
// if (num_tagged[INDEX_ID_NULL] == 0) {
// BKE_report(op->reports, RPT_INFO, "No orphaned data-blocks to purge");
// return OPERATOR_CANCELLED;
// }
//}
//BKE_id_multi_tagged_delete(bmain);
//BKE_reportf(op->reports, RPT_INFO, "Deleted %d data-block(s)", num_tagged[INDEX_ID_NULL]);
///* XXX: tree management normally happens from draw_outliner(), but when
// * you're clicking to fast on Delete object from context menu in
// * outliner several mouse events can be handled in one cycle without
// * handling notifiers/redraw which leads to deleting the same object twice.
// * cleanup tree here to prevent such cases. */
//if ((area != NULL) && (area->spacetype == SPACE_OUTLINER)) {
// outliner_cleanup_tree(soops);
//}
//DEG_relations_tag_update(bmain);
//WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
//WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
/////////////////////////////////////////////////
ntreeCoviseExecTree(C, ntree);
/////////////////////////////////////////////////
return OPERATOR_FINISHED;
}
......@@ -652,7 +697,7 @@ void NODE_OT_exec_node_tree(wmOperatorType *ot)
ot->exec = exec_node_tree_exec;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER;// | OPTYPE_UNDO;
// prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Tree Type", "");
// RNA_def_enum_funcs(prop, exec_node_tree_type_itemf);
......
......@@ -146,6 +146,8 @@ static void node_covise_blenderrenderer_execute(void *data, int thread, struct b
blenderRenderer->set_params(ncdsd);
//distributedObject->incRefCount();
blenderRenderer->clear_material();
blenderRenderer->receiveAddObjectMessage(distributedObject, distributedObject->getName(), false);
blenderRenderer->update_scene();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment