Skip to content

Commit

Permalink
Better openings, speed and stability improvements
Browse files Browse the repository at this point in the history
- openings(cutting components) now still cut holes when overlapping and
on/over the face edges
- Speed improvements by replacing individual "add_face" calls with
"fill_from_mesh"
- Stability improvements because of better use of observers.
- Removed the GUID field from the menu because it doesn't match the IFC
export GUID
- fix side-faces normal direction in openings
  • Loading branch information
janbrouwer committed Jan 15, 2016
1 parent 5afe576 commit 67e4990
Show file tree
Hide file tree
Showing 10 changed files with 714 additions and 549 deletions.
14 changes: 2 additions & 12 deletions bim-tools.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bim-tools.rb
#
# Copyright (C) 2015 Jan Brouwer <[email protected]>
# Copyright (C) 2016 Jan Brouwer <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -15,16 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# roadmap:
# columns

# roadmap 0.14:
# fix side-faces normal direction in openings
# fix project properties(different way of reading/writing properties? one at a time instead of array?)
# get rid of entitiesobservers
# improve IFC export
# speed up hidden edges

require 'sketchup.rb'
require 'extensions.rb'

Expand All @@ -43,7 +33,7 @@ module BimTools

# Create Extension
bimtools = SketchupExtension.new "bim-tools", File.join( PATH, 'bim-tools_loader.rb' )
bimtools.version = '0.13.4'
bimtools.version = '0.14.0'
bimtools.description = "Tools to create building parts and export these to IFC."
Sketchup.register_extension bimtools, true
end # module BimTools
Expand Down
32 changes: 6 additions & 26 deletions bim-tools/clsBtProject.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# clsBtProject.rb
#
# Copyright (C) 2012 Jan Brouwer <[email protected]>
# Copyright (C) 2016 Jan Brouwer <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -58,7 +58,6 @@ def initialize(id=nil, name=nil, description=nil)
set_organisation_name #@organisation_name = @default.get("organisation_name")
set_organisation_description #@organisation_description = @default.get("organisation_description")


# set initial value for toggle button
toggle_value = @model.get_attribute "bim-tools", "visible_geometry"

Expand All @@ -72,10 +71,10 @@ def initialize(id=nil, name=nil, description=nil)
@visible_geometry = true
end

@lib = ClsBtLibrary.new # would ClsBtEntities be a better name?
@lib = ClsBtLibrary.new #(?) would ClsBtEntities be a better name?

@source_tracker = SourceTracker.new(self)
#id=#("id") # do or do not use "project" in method names?
#id=#("id") #(?) do or do not use "project" in method names?
name=()#("name")
description=()#("description")

Expand Down Expand Up @@ -174,29 +173,10 @@ def new_guid
guid = '';22.times{|i|guid<<'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$'[rand(64)]}
return guid
end
# def name=(name=nil)
#
# # check if active_model already contains BtProject / IFC data and pass these to the project instance.
# if name.nil?
# @name = @model.get_attribute "ifc", "IfcProject_Name", nil
# else
# @name = name
# @model.set_attribute "ifc", "IfcProject_Name", @name
# end
# end
# def description=(description=nil)
#
# # check if active_model already contains BtProject / IFC data and pass these to the project instance.
# if description.nil?
# @description = @model.get_attribute "ifc", "IfcProject_Description", nil
# else
# @description = description
# @model.set_attribute "ifc", "IfcProject_Description", @description
# end
# end
# this method is used to update / set the value of several project-data-fields(such as name and description)
def set_project_data(new_value, old_value, ifc_name, default_name)
# new_value = (optional) new name
# old_value = current name
# ifc_name = name of the IFC value field in the project´s ifc attributes
Expand Down Expand Up @@ -364,7 +344,7 @@ def refresh_geometry(bt_entity)
UI.stop_timer( @delay )
# temporarily turn off observers to prevent creating geometry multiple times
Brewsky::BimTools::ObserverManager.toggle
Brewsky::BimTools::ObserverManager.suspend
@model = Sketchup.active_model
Expand Down Expand Up @@ -433,7 +413,7 @@ def refresh_geometry(bt_entity)
@model.active_view.refresh # Refresh model
# switch observers back on
Brewsky::BimTools::ObserverManager.toggle
Brewsky::BimTools::ObserverManager.resume
}
end
Expand Down
30 changes: 29 additions & 1 deletion bim-tools/lib/ObserverManager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ObserverManager.rb
#
# Copyright (C) 2015 Jan Brouwer <[email protected]>
# Copyright (C) 2016 Jan Brouwer <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -135,6 +135,20 @@ def deactivate

# what to do when component is placed? cut hole if possible.
def onElementAdded(entities, entity)
if entity.is_a?(Sketchup::ComponentInstance)
unless entity.glued_to.nil?
source = entity.glued_to

# run only if added entity cuts_opening
if entity.definition.behavior.cuts_opening?

# check if entity is part of a building element
if bt_entity = BimTools.active_BtProject.library.source_to_bt_entity(BimTools.active_BtProject, source)
bt_entity.update_geometry
end
end
end
end

# if cutting-component?
# if glued?
Expand Down Expand Up @@ -250,6 +264,20 @@ def self.toggle
self.load
end
end

#temporarily deactivate observers
def self.suspend
@app_observer.deactivate
@entities_observer.deactivate
@selection_observer.deactivate
end

#reactivate suspended observers
def self.resume
@app_observer.activate
@entities_observer.activate
@selection_observer.activate
end
end # module ObserverManager
end # module BimTools
end # module Brewsky
69 changes: 33 additions & 36 deletions bim-tools/lib/clsBuildingElement.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# clsBuildingElement.rb
#
# Copyright (C) 2012 Jan Brouwer <[email protected]>
# Copyright (C) 2016 Jan Brouwer <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -39,10 +39,6 @@ def deleted?

# if source object is unrecoverable, self_destruct bt_entity
def self_destruct

# get connecting entities for updating geometry after deletion
edges = self.source.edges # works only for face!

@deleted = true
unless @source.deleted?
source.hidden= false
Expand All @@ -51,27 +47,22 @@ def self_destruct
if @source.attribute_dictionaries
@source.attribute_dictionaries.delete 'ifc'
end

# get connecting entities for updating geometry after deletion
edges = self.source.edges # works only for face!

# update connecting bt_entities
find_linked_elements()
end

unless @geometry.deleted?
@geometry.erase!
end

# remobe bt_entity from library
@project.library.entities.delete(self)

# update connecting geometry after deletion
a_connecting_faces = Array.new # Array to hold al connecting faces
edges.each do |edge|
unless edge.deleted?
edge.faces.each do |face|
# add only bt-source-faces to array, bt-entities must not react to "normal" faces
if @project.library.source_to_bt_entity(@project, face)
a_connecting_faces << @project.library.source_to_bt_entity(@project, face) # shorter??????
end
end
end
end
@project.bt_entities_set_geometry(a_connecting_faces)
@project.bt_entities_set_geometry(@linked_elements)
end

# hide OR geometry OR source
Expand Down Expand Up @@ -146,9 +137,21 @@ def element_type=(type)

# checks if the source entity is valid, and if not searches for new source entity
def check_source
if @source.deleted?
@project.source_recovery
if @deleted == true
self_destruct
return false
else
if @source.deleted?

# when to use source_recovery or find_source????????????????
#@project.source_recovery
if find_source == false
self_destruct
return false
end
end
end
return true
end

# checks if the geometry group is valid, and if not creates new geometry
Expand All @@ -158,14 +161,19 @@ def check_geometry
end
end

# (?) search only in root entities collection?
# if source object = renamed, find the new name
def find_source
entities = Sketchup.active_model.entities
entities.each do |entity|
guid = entity.get_attribute "ifc", "guid"
if guid == @guid
@source = entity
break
entities.each do |ent|
if ent.is_a? Sketchup::Face # (!) only faces?
guid = ent.get_attribute "ifc", "guid"
if guid == @guid
@source = ent
return @source
else
return false
end
end
end
end
Expand All @@ -185,17 +193,6 @@ def find_source
def set_guid
@guid = @project.new_guid
end
def find_bt_entity_for_face(source)
bt_entity = nil
@project.library.entities.each do |ent|
if source == ent.source # als het vlak voorkomt in de bt-library
bt_entity = ent
break
end
end
bt_entity
return bt_entity
end
end
end # module BimTools
end # module Brewsky
Loading

0 comments on commit 67e4990

Please sign in to comment.