Skip to content

Commit 90b86e7

Browse files
Merge commit 'e624a68'
2 parents 0cb199a + e624a68 commit 90b86e7

File tree

9 files changed

+290
-443
lines changed

9 files changed

+290
-443
lines changed

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ endif
119119
all: all-without-models
120120
$(MAKE) models
121121

122-
all-without-models: ecolab-libs lib/libecolab$(ECOLIBS_EXT).a bin/ecolab$(ECOLIBS_EXT)
122+
ifndef MXE
123+
ECOLAB_INTERPRETER=bin/ecolab$(ECOLIBS_EXT)
124+
endif
125+
126+
all-without-models: ecolab-libs lib/libecolab$(ECOLIBS_EXT).a $(ECOLAB_INTERPRETER)
123127
-$(CHMOD) a+x $(SCRIPTS)
124128
# copy in the system built TCL library
125129
ifdef MXE
@@ -174,9 +178,13 @@ lib/libecolab$(ECOLIBS_EXT).a: $(OBJS) $(LIBMODS) graphcode
174178
ifeq ($(OS),Darwin)
175179
ranlib $@
176180
endif
181+
ifeq ($(OS),Linux)
182+
ifndef MXE
177183
$(CPLUSPLUS) -shared -Wl,-soname,libecolab$(ECOLIBS_EXT).so.$(SOVERSION) $(OBJS) $(LIBMODS) graphcode/*.o $(LIBS) -o lib/libecolab$(ECOLIBS_EXT).so.$(SOVERSION)
178184
cd lib; ln -sf libecolab$(ECOLIBS_EXT).so.$(SOVERSION) libecolab$(ECOLIBS_EXT).so
179185
cd lib; ln -sf libecolab$(ECOLIBS_EXT).so.$(SOVERSION) ecolab.so
186+
endif
187+
endif
180188

181189
$(MODS:%=lib/%): lib/%: src/%
182190
cp $< $@
@@ -269,11 +277,13 @@ UNURAN_LIB=$(firstword $(call search,lib*/libunuran.a))
269277

270278
$(ECOLAB_HOME)/$(MCFG):
271279
@rm -f $(MCFG)
280+
ifndef MXE
272281
# absolute dependencies
273282
@if ! $(PKG_CONFIG) --exists python3; then \
274283
echo "Error: Cannot find Python libs - please install python3-dev"; \
275284
exit 1; \
276285
fi
286+
endif
277287
# optional dependecies
278288
@if [ -n "$(call search,lib*/tclConfig.sh)" ]; then echo TCL=1>>$(MCFG); fi
279289
@if [ -n "$(call search,lib*/tkConfig.sh)" ]; then echo TK=1>>$(MCFG); fi

classdesc

include/Makefile

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@ DPCPP=
2626
# enables ecolab for the MXE environment
2727
MXE=
2828

29+
# choose 32 bits by preference
30+
ifdef MXE
31+
MXE_32bit=$(shell if which i686-w64-mingw32.shared-g++>&/dev/null; then echo 1; fi)
32+
MXE_64bit=$(shell if which x86_64-w64-mingw32.shared-g++>&/dev/null; then echo 1; fi)
33+
ifeq ($(MXE_32bit),1)
34+
MXE_PREFIX=i686-w64-mingw32.shared
35+
else
36+
ifeq ($(MXE_64bit),1)
37+
MXE_PREFIX=x86_64-w64-mingw32.shared
38+
else
39+
$(error "MXE compiler not found")
40+
endif
41+
endif
42+
43+
# force 64 bit build
44+
ifdef MXE64
45+
MXE_64bit=$(shell if which x86_64-w64-mingw32.shared-g++>&/dev/null; then echo 1; fi)
46+
ifeq ($(MXE_64bit),1)
47+
MXE_PREFIX=x86_64-w64-mingw32.shared
48+
else
49+
$(error "MXE compiler not found")
50+
endif
51+
endif
52+
53+
2954
FLAGS+=-DECOLAB_HOME=\"$(ECOLAB_HOME)\"
3055

3156
ifdef MPI_DEBUG
@@ -66,6 +91,7 @@ DIRS=$(ECOLAB_HOME) $(HOME)/usr /usr/local /opt/local /usr/X11R6
6691
# a search mechanism to find a particular file
6792
# use as $(call search,name)
6893
ifdef MXE
94+
DIRS+=$(dir `which $(MXE_PREFIX)-g++`)
6995
search=$(firstword $(foreach dir,$(DIRS),$(wildcard $(dir)/$(1))))
7096
else
7197
search=$(firstword $(foreach dir,$(DIRS) /usr,$(wildcard $(dir)/$(1))))
@@ -123,30 +149,6 @@ CC:=ccache $(CC)
123149
CPLUSPLUS:=ccache $(CPLUSPLUS)
124150
endif
125151

126-
# choose 32 bits by preference
127-
ifdef MXE
128-
MXE_32bit=$(shell if which i686-w64-mingw32.shared-g++>&/dev/null; then echo 1; fi)
129-
MXE_64bit=$(shell if which x86_64-w64-mingw32.shared-g++>&/dev/null; then echo 1; fi)
130-
ifeq ($(MXE_32bit),1)
131-
MXE_PREFIX=i686-w64-mingw32.shared
132-
else
133-
ifeq ($(MXE_64bit),1)
134-
MXE_PREFIX=x86_64-w64-mingw32.shared
135-
else
136-
$(error "MXE compiler not found")
137-
endif
138-
endif
139-
140-
# force 64 bit build
141-
ifdef MXE64
142-
MXE_64bit=$(shell if which x86_64-w64-mingw32.shared-g++>&/dev/null; then echo 1; fi)
143-
ifeq ($(MXE_64bit),1)
144-
MXE_PREFIX=x86_64-w64-mingw32.shared
145-
else
146-
$(error "MXE compiler not found")
147-
endif
148-
endif
149-
150152
GCC=1
151153
FLAGS+= -DNO_FWD_DECLARE_STL -DMXE -DSTATIC_BUILD
152154
CC=$(MXE_PREFIX)-gcc
@@ -590,7 +592,8 @@ LINK+=$(OPT)
590592
LIBMODS=
591593

592594
# modules to include on the MODLINK command line
593-
ALWAYSLINK=tcl_arrays tclgraph analysis random cairo_types plot
595+
#ALWAYSLINK=analysis random cairo_types plot
596+
ALWAYSLINK=
594597

595598
# for some reason, the -u option doesn't work with MXE
596599
ifdef MXE

include/cairo_base.h

Lines changed: 5 additions & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#include "arrays.h"
1616

1717
#include <cairo/cairo.h>
18-
#ifdef TK
19-
#include <tk.h>
20-
#endif
2118
#include <vector>
2219
#include <string>
2320
#include <limits>
@@ -190,225 +187,6 @@ namespace ecolab
190187
}
191188
};
192189

193-
#ifdef TK
194-
struct PhotoImageBlock: public Tk_PhotoImageBlock
195-
{
196-
PhotoImageBlock(): transparency(true) {}
197-
PhotoImageBlock(int x, int y, bool transparency):
198-
transparency(transparency)
199-
{
200-
pixelPtr=NULL;
201-
width=x;
202-
height=y;
203-
cairo_format_t format = transparency?
204-
CAIRO_FORMAT_ARGB32: CAIRO_FORMAT_RGB24;
205-
pitch = cairo_format_stride_for_width(format, width);
206-
pixelSize=4;
207-
for (int i=0; i<3; ++i) offset[i]=2-i;
208-
offset[3]=3;
209-
}
210-
bool transparency;
211-
};
212-
213-
class TkPhotoSurface: public Surface
214-
{
215-
Tk_PhotoHandle photo;
216-
std::vector<unsigned char> imageData;
217-
PhotoImageBlock imageBlock;
218-
public:
219-
/// if true, then blits do not clear previous photo contents
220-
bool compositing;
221-
222-
double width() const override {return imageBlock.width;}
223-
double height() const override {return imageBlock.height;}
224-
void clear() override {
225-
if (imageBlock.transparency)
226-
// make it transparent
227-
memset(imageData.data(),0,imageData.size());
228-
else
229-
// make it white
230-
memset(imageData.data(),255,imageData.size());
231-
}
232-
TkPhotoSurface(Tk_PhotoHandle photo, bool transparency=true):
233-
photo(photo), compositing(false)
234-
{
235-
init(transparency);
236-
}
237-
238-
void init(bool transparency=true)
239-
{
240-
int width, height;
241-
Tk_PhotoGetSize(photo, &width, &height);
242-
imageBlock = PhotoImageBlock(width, height, transparency);
243-
imageData.resize(size_t(imageBlock.pitch) * imageBlock.height);
244-
imageBlock.pixelPtr = imageData.data();
245-
246-
surface( cairo_image_surface_create_for_data
247-
(imageData.data(), transparency?
248-
CAIRO_FORMAT_ARGB32: CAIRO_FORMAT_RGB24,
249-
width, height, imageBlock.pitch));
250-
}
251-
252-
void resize(size_t width, size_t height) override
253-
{
254-
//#if TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION < 5
255-
// Tk_PhotoSetSize(photo, width, height);
256-
//#else
257-
// Tk_PhotoSetSize(interp(), photo, width, height);
258-
//#endif
259-
// init(imageBlock.transparency);
260-
}
261-
262-
/// copy the cairo output into the TkPhoto
263-
void blit(unsigned x, unsigned y, unsigned width, unsigned height) override
264-
{
265-
// imageBlock.pixelPtr=&imageData[x*imageBlock.pixelSize + y*imageBlock.pitch];
266-
// if (width != unsigned(imageBlock.width) ||
267-
// height != unsigned(imageBlock.height))
268-
//#if TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION < 5
269-
// Tk_PhotoSetSize(photo, width, height);
270-
// Tk_PhotoPutBlock
271-
// (photo, &imageBlock, 0, 0, width, height,
272-
// compositing? TK_PHOTO_COMPOSITE_OVERLAY:TK_PHOTO_COMPOSITE_SET);
273-
//#else
274-
// Tk_PhotoSetSize(interp(), photo, width, height);
275-
// Tk_PhotoPutBlock(interp(), photo, &imageBlock, 0, 0, width, height,
276-
// compositing? TK_PHOTO_COMPOSITE_OVERLAY:TK_PHOTO_COMPOSITE_SET);
277-
//#endif
278-
}
279-
void blit() override {blit(0,0,imageBlock.width, imageBlock.height);}
280-
void requestRedraw() override {blit();}
281-
};
282-
283-
class CairoImage
284-
{
285-
CLASSDESC_ACCESS(CairoImage);
286-
protected:
287-
void resize(size_t width, size_t height);
288-
289-
/// resize photo and surface
290-
/// Complaint draw() routines should set the transformation
291-
/// matrix to this, rather than the identity matrix, to allow
292-
/// scaling. identMatrix is automatically translated to the
293-
/// centre of the cairoSurface
294-
double xScale, yScale; ///< track scale requests
295-
double m_scale, rotation;///< track setMatrix requests
296-
297-
public:
298-
/// configSpecs for this type (itemconfigure options)
299-
static Tk_ConfigSpec configSpecs[];
300-
301-
SurfacePtr cairoSurface;
302-
303-
/// sets the transformation matrix so that user coordinates are
304-
/// centered on the bitmap, and scaled according to the current
305-
/// scale value
306-
void initMatrix();
307-
308-
/// implementation of -scale and -rotation item options
309-
void setMatrix(double scale, double rotation)
310-
{m_scale=scale, this->rotation=rotation;}
311-
312-
// apply an additional scale transformation
313-
void scale(double xScale, double yScale) {
314-
if (xScale!=1 || yScale!=1)
315-
{this->xScale*=xScale; this->yScale*=yScale;}
316-
}
317-
318-
CairoImage(): xScale(1), yScale(1) {setMatrix(1,0);}
319-
CairoImage(const SurfacePtr& cairoSurface):
320-
xScale(1), yScale(1), cairoSurface(cairoSurface) {setMatrix(1,0);}
321-
322-
virtual ~CairoImage() {}
323-
324-
void attachToImage(const std::string& imgName);
325-
326-
/// distance x, y is from CairoItem (in device coordinates)
327-
double distanceFrom(double x, double y) const;
328-
329-
/// bounding box (in device coordinates) of the clip region
330-
virtual ecolab::array_ns::array<double> boundingBox();
331-
332-
/// return -1, 0, 1 if rectangle is outside, partially inside or
333-
/// completely inside the clip. Arguments are in device
334-
/// coordinates
335-
int inClip(double x0, double y0, double x1, double y1) const;
336-
337-
/// draw this item. @throw nothing.
338-
virtual void draw()=0;
339-
void redrawIfSurfaceTooSmall();
340-
void blit() {cairoSurface->blit();}
341-
342-
};
343-
344-
/// internal structure used for Tk Canvas cairo image items
345-
struct ImageItem {
346-
Tk_Item header; /* Generic stuff that's the same for all
347-
* types. MUST BE FIRST IN STRUCTURE. */
348-
Tk_Canvas canvas; /* Canvas containing the image. */
349-
double x, y; /* Coordinates of positioning point for
350-
* image. */
351-
double scale; /* scale = 1 means cairo drawing
352-
coordinates in the range [-1,1] map
353-
to [x0,x1], [y0,y1] of the image
354-
pixmap */
355-
356-
double rotation; /* rotation opf cairo user coordinate
357-
with respect to pixmap coordinates,
358-
in radians */
359-
360-
Tk_Anchor anchor; /* Where to anchor image relative to (x,y). */
361-
char *imageString; /* String describing -image option
362-
* (malloc-ed). NULL means no image right
363-
* now. */
364-
char *activeImageString; /* String describing -activeimage option.
365-
* NULL means no image right now. */
366-
char *disabledImageString; /* String describing -disabledimage option.
367-
* NULL means no image right now. */
368-
Tk_Image image; /* Image to display in window, or NULL if no
369-
* image at present. */
370-
Tk_Image activeImage; /* Image to display in window, or NULL if no
371-
* image at present. */
372-
Tk_Image disabledImage; /* Image to display in window, or NULL if no
373-
* image at present. */
374-
bool redrawing; // set this flag to disable enqueing of eventually redraw
375-
CairoImage *cairoItem;
376-
};
377-
378-
namespace TkImageCode
379-
{
380-
int CreateImage(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr,
381-
int objc,Tcl_Obj *CONST objv[],Tk_ConfigSpec[]);
382-
void DeleteImage(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display);
383-
/// generic configure function, given a particular \a configSpecs
384-
int configureCairoItem(Tcl_Interp *interp, Tk_Canvas canvas,
385-
Tk_Item *itemPtr, int objc,
386-
Tcl_Obj *const objv[],
387-
int flags, Tk_ConfigSpec configSpecs[]);
388-
void ComputeImageBbox(Tk_Canvas canvas, ImageItem *imgPtr);
389-
}
390-
391-
/// factory method for creating a CairoImage, to be used for
392-
/// creating Tk canvas itemTypes
393-
template <class C>
394-
int createImage(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr,
395-
int objc,Tcl_Obj *CONST84 objv[])
396-
{
397-
if (TkImageCode::CreateImage(interp,canvas,itemPtr,objc,objv,C::configSpecs)==TCL_OK)
398-
{
399-
ImageItem* imgPtr=(ImageItem*)(itemPtr);
400-
imgPtr->cairoItem = new C;
401-
imgPtr->cairoItem->setMatrix(imgPtr->scale, imgPtr->rotation);
402-
TkImageCode::ComputeImageBbox(canvas, imgPtr);
403-
return TCL_OK;
404-
}
405-
TkImageCode::DeleteImage(canvas, itemPtr,
406-
Tk_Display(Tk_CanvasTkwin(canvas)));
407-
return TCL_ERROR;
408-
}
409-
410-
const Tk_ItemType& cairoItemType();
411-
#endif // #ifdef TK
412190

413191
}
414192
}
@@ -426,4 +204,9 @@ namespace classdesc_access
426204

427205
#include "cairo_base.cd"
428206
#endif
207+
208+
#ifdef TK
209+
#include "tk_cairo.h"
210+
#endif
211+
429212
#endif

0 commit comments

Comments
 (0)