#            P I C T U R E T Y P E B A S E . I T C L
# BRL-CAD
#
# Copyright (c) 2004-2023 United States Government as represented by
# the U.S. Army Research Laboratory.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this file; see the file named COPYING for more
# information.
#
###
#
# This is the base class for the various picture types (duh!).
#  It provides the shared methods.
#

#
# Required packages
#
package require Itcl
package require Itk
package require Iwidgets

namespace eval RtWizard {

    package provide PictureTypeBase 1.0

    #
    # Required packages
    #

    # None!

    #
    # The PictureTypeBase class should not be instantiated!
    #
    ::itcl::class PictureTypeBase {

	public {
	    constructor {args} {}

	    #
	    # These methods handle when a picture type is chosen
	    # or replaced.
	    #
	    method activate {}
	    method deactivate {}

	    #
	    # Accessor methods
	    #
	    method getTitle {} {
		return $title
	    }

	    method getSampleImage {} {
		return $sampleImage
	    }

	    method getDescText {} {
		return $descText
	    }

	    method getHelpStr {} {
		return $helpStr
	    }

	    #
	    # These methods generate pictures. They query the
	    # individual pages for the information they need.
	    #
	    method rtimage {w h}
	    method preview {}
	    method fullSize {}
	}

	protected {
	    method hexToRGB {hexRGB} {}

	    variable title
	    variable sampleImage
	    variable descText
	    variable helpStr
	    variable introText
	    variable startPage
	}

	private {
	    variable waiting ""
	}
    }

    #--------------------#
    #   Public Methods   #
    #--------------------#
    #
    # constructor - Loads all of the information necessary
    #               to support this image type. This includes
    #               the sample image, the descriptive text,
    #
    itcl::body PictureTypeBase::constructor { args } {
	#
	# Protect against instantiation. This is an _abstract_
	# class.
	#
	set type [namespace tail [$this info class]]
	if { $type == "PictureTypeBase" } {
	    error "Can't instantiate the abstract PictureTypeBase class."
	}

	#
	# The support directory name is the same as the
	# class type.
	#

	#
	# Load the title string
	#
	set title ""

	set success 0

	foreach i $::auto_path {
	    set dir [file join $i {..} tclscripts rtwizard examples $type ]
	    if {[file exists [file join $dir title.txt ]]} {
		set fd [open [file join $dir title.txt] r]
		set title [read -nonewline $fd]
		close $fd
		set success 1
		break
	    }
	}

	if { $success == 0 } {
	    puts "Could not find tclscripts/rtwizard/examples/$type/title.txt\ninautopath:\n $::auto_path"
	    exit
	}

	#
	# Create an image object to hold the sample image.
	#
	set tmpFile [ file join $dir preview.small.gif ]
	set sampleImage [ image create photo -file $tmpFile ]

	#
	# Load the text that describes the sample.
	#
	set tmpFile [file join $dir desc.txt]
	set fd [open $tmpFile r]
	set descText [read -nonewline $fd]
	close $fd

	#
	# Load the help string.
	#
	set tmpFile [file join $dir helpstr.txt]
	set fd [open $tmpFile r]
	set helpStr [read -nonewline $fd]
	close $fd

	#
	# Load the introtext.
	#
	set tmpFile [file join $dir intro.txt]
	set fd [open $tmpFile r]
	set introText [read -nonewline $fd]
	close $fd
    }

    #
    # activate - called when this picture type is selected.
    #
    itcl::body PictureTypeBase::activate { } {
	append msg "PictureTypeBase::activate called" \
	    " - should be overloaded by derived class."
	error $msg
    }

    #
    # deactivate - called when this picture type is deselected.
    #
    itcl::body PictureTypeBase::deactivate { } {
	append msg "PictureTypeBase::deactivate called" \
	    " - should be overloaded by derived class."
	error $msg
    }

    #
    # rtimage - responsible for generating the actual image
    #
    itcl::body PictureTypeBase::rtimage {w h} {
	append msg "PictureTypeBase::rtimage called" \
	    " - should be overloaded by derived class."
	error $msg
    }

    #
    # preview - generates a 1/4 size preview image
    #
    itcl::body PictureTypeBase::preview { } {
	append msg "PictureTypeBase::preview called" \
	    " - should be overloaded by derived class."
	error $msg
    }

    #
    # fullSize - generates the full size image
    #
    itcl::body PictureTypeBase::fullSize { } {
	append msg "PictureTypeBase::fullSize called" \
	    " - should be overloaded by derived class."
	error $msg
    }

    #-------------------#
    # Protected Methods #
    #-------------------#

    #
    # hexToRGB - converts an RGB color in hex #rrggbb format to
    #            decimal {rrr ggg bbb} format
    #
    itcl::body PictureTypeBase::hexToRGB {hexRGB} {

	scan [string range $hexRGB 1 2] "%x" redDec
	scan [string range $hexRGB 3 4] "%x" greenDec
	scan [string range $hexRGB 5 6] "%x" blueDec

	return [list $redDec $greenDec $blueDec]
    }
}; # end namespace


# Local Variables:
# mode: Tcl
# tab-width: 8
# c-basic-offset: 4
# tcl-indent-level: 4
# indent-tabs-mode: t
# End:
# ex: shiftwidth=4 tabstop=8
