# Supports Organizer.rb
=begin rdoc

= AddOrthoScenes.rb
Copyright 2004-2014 by Rick Wilson - All Rights Reserved

== Disclaimer
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

== License
This software is distributed under the Smustard End User License Agreement
http://www.smustard.com/eula

== Information
Author:: Rick Wilson
Organization:: Smustard
Name:: AddOrthoScenes
Version:: 1.2.1
SU Version:: 4.0
Date:: 2014-05-16
Description:: Add scenes orthographically by entering x,y,z offsets

Usage::
* 1:: select "View>Add Ortho Scenes" and answer the prompts
	
History::
* 1.0.0:: 2004-08-30
	* first version - released as "add_pages.rb"
* 1.1.0:: 2006-06-28
	* added units support - reads default units for distance
* 1.2.0:: 2014-05-02
	* wrapped in module Smustard, added a class
	* packaged for the EW, renamed to AddOrthoScenes
* 1.2.1:: 2014-05-16
	* version 1.2.0 works in SU 2014, but a code block didn't work in earlier versions (due to changes in Ruby).  Fixed this to work in all versions.


ToDoList::
	* 
	* 

=end



module Smustard
	
	if ($smustard_toolbar)	# legacy programs creating a global
		Smustard::Toolbar = $smustard_toolbar unless Smustard.constants.include?("Toolbar")
	else
		Smustard::Toolbar = UI::Toolbar.new("Smustard") unless Smustard.constants.include?("Toolbar")
	end

class AddOrthoScenes
	
	@@build_ui = true
	@@cmd_add_ortho_scenes = UI::Command.new("Add Ortho Scenes") { Smustard::AddOrthoScenes.add() }
	@@cmd_add_ortho_scenes.tooltip = "Add Ortho Scenes"
	@@cmd_add_ortho_scenes.status_bar_text = "Add scenes orthographically by entering x,y,z offsets"
	@@cmd_add_ortho_scenes.large_icon = "AddOrthoScenesLarge.png"
	@@cmd_add_ortho_scenes.small_icon = "AddOrthoScenesSmall.png"
	
	@@addscenes_cams = 1
	@@addscenes_x = "0"
	@@addscenes_y = "0"
	@@addscenes_z = "0"
	
	def AddOrthoScenes.add()
		
		model = Sketchup.active_model
		view = model.active_view
		pages = model.pages
		cam = view.camera
		
		eye = cam.eye
		target = cam.target
		up = cam.up
		pers = cam.perspective?
		fov = cam.fov
		
		prompts = ["Scenes","x Interval","y Interval","z Interval"]
		
		if not @@addscenes_x
			values = []
		else
			values = [@@addscenes_cams,@@addscenes_x,@@addscenes_y,@@addscenes_z]
		end
		
		results = inputbox(prompts,values,"Add Pages")
		
		@@addscenes_cams = results[0].to_i
		@@addscenes_x = results[1].to_l
		@@addscenes_y = results[2].to_l
		@@addscenes_z = results[3].to_l
		
		t = Geom::Transformation.new(Geom::Vector3d.new(@@addscenes_x,@@addscenes_y,@@addscenes_z))
		model.start_operation("Add Ortho Scenes")
		0.upto(@@addscenes_cams-1) do |n|
			eye.transform!(t)
			target.transform!(t)
			newCamera = Sketchup::Camera.new(eye,target,up,pers,fov)
			view.camera = newCamera
			pages.add
		end
		model.commit_operation
	end
	
	
	
	def AddOrthoScenes.build_ui()
		
		if @@build_ui
			@@build_ui = false
			UI.menu("View").add_item(@@cmd_add_ortho_scenes)
			Smustard::Toolbar.add_item(@@cmd_add_ortho_scenes)
		end		
		
	end
	
	

end # class AddOrthoScenes

end #module Smustard


unless file_loaded?(__FILE__)
	file_loaded(__FILE__)
	Smustard::AddOrthoScenes.build_ui()
end