Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoXtMaterialEditor.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Alain Dumesny (MMM yyyy)
25** Modified by : David Mott (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50#ifdef SOQT
51# include <Inventor/Qt/SoQtMaterialEditor.h>
52#elif defined _WIN32
53# include <Inventor/Win/SoWinMaterialEditor.h>
54#else // _WIN32
55
56#ifndef _SO_XT_MATERIAL_EDITOR_
57#define _SO_XT_MATERIAL_EDITOR_
58
59#include <Xm/Xm.h>
60#include <Inventor/SbBasic.h>
61#include <Inventor/misc/SoCallbackList.h>
62#include <Inventor/Xt/SoXtComponent.h>
63
64class SoBaseColor;
65class SoXtClipboard;
66class SoXtColorEditor;
67class SoNodeSensor;
68class SoSensor;
70class SoMaterial;
72class SoPathList;
73class SoXtRenderArea;
74class SoSelection;
75class SoXtColorSlider;
76class SoMFColor;
77class SbColor;
78class SoBase;
79class SoSeparator;
80class SoNode;
81class SoSFColor;
82
83// callback function prototypes
85typedef void SoXtMaterialEditorCB(void *userData, const SoMaterial *mtl);
86
88//
89// Class: SoXtMaterialEditor
90//
91// This editor lets you interactively edit a material
92//
94
158 public:
173
178 SoWidget parent = NULL,
179 const char *name = NULL,
180 SbBool buildInsideParent = TRUE);
185
190 void attach(SoMaterial *material, int index = 0);
191
195 void detach();
199 SbBool isAttached() { return (material != NULL); }
200
206 inline void addMaterialChangedCallback(
207 SoXtMaterialEditorCB *f,
208 void *userData = NULL);
212 inline void removeMaterialChangedCallback(
213 SoXtMaterialEditorCB *f,
214 void *userData = NULL);
215
219 void setUpdateFrequency(SoXtMaterialEditor::UpdateFrequency freq);
225
226 // Redefine these since there are multiple windows -
227 // the color editor, directional light editor, and this component
228 virtual void show();
229 virtual void hide();
230
234 void setMaterial(const SoMaterial &mtl);
235
239 const SoMaterial & getMaterial() const { return *localMaterial; }
240
241 private:
242
243 // This constructor takes a boolean whether to build the widget now.
244 // Subclasses can pass FALSE, then call SoXtMaterialEditor::buildWidget()
245 // when they are ready for it to be built.
246 SoEXTENDER
248 SoWidget parent,
249 const char *name,
250 SbBool buildInsideParent,
251 SbBool buildNow);
252
253 SoWidget buildWidget(SoWidget parent);
254
255 // redefine these
256 virtual SbString getDefaultWidgetName() const;
257 virtual SbString getDefaultTitle() const;
258 virtual SbString getDefaultIconTitle() const;
259
260 private:
261 // attach vars
262 SoMaterial *material; // material we are editing
263 SoMaterial *imat;
264 int index; // material index number
265 SoNodeSensor *sensor;
266 SoCallbackList *callbackList;
267 SoWidget acceptButton, diamondButtons[4], radioButtons[4];
268 SoXtMaterialEditor::UpdateFrequency updateFreq;
269
270 // widgets to edit the material
271 SoWidget mgrWidget; // topmost widget
272 SoXtColorEditor *colorEditor;
273 SoXtColorSlider *sliders[6];
274 SbBool changedIt[6];
275 SoXtMaterialList *materialList;
276 SbBool ignoreCallback; // TRUE while callback should be ignored
277 SbBool openMaterialList;
278 static void colorEditorCloseCB(void *, SoXtComponent *);
279 static void materialListCloseCB(void *, SoXtComponent *);
280
281 // copy/paste support
282 SoXtClipboard *clipboard;
283
284 // local scene vars
285 SoXtRenderArea *renderArea;
286 SoMaterial *localMaterial; // local copy of the material
287 SoDirectionalLight *light0;
288 SoDirectionalLight *light1;
289 SoBaseColor *tileColor;
290 SoSeparator *root;
291
292 // keep the menu items around so we can update them before menu display
293 SoWidget *menuItemsList;
294
295 int32_t activeColor; // field which color editor edits
296
297 // update the sliders/colorEditor based on the local material
298 void updateLocalComponents();
299
300 // update the colorEditor based on the activeColor flag
301 void updateColorEditor(SbBool updateTitle = FALSE);
302
303 // update a color slider (amb/diff/spec/emiss) based of a material color
304 // (split the base color from the intensity).
305 void updateColorSlider(SoXtColorSlider *, const float rgb[3]);
306
307 // update a material field when a color slider changes.
308 void updateMaterialColor(
309 SoMFColor *editMtlColor,
310 SoMFColor *localMtlColor,
311 const float *rgb,
312 float intensity);
313 void updateMaterialColor(
314 SoSFColor *editMtlColor,
315 SoMFColor *localMtlColor,
316 const float *rgb,
317 float intensity);
318
319 // copies mat2 onto mat1
320 void copyMaterial(SoMaterial *mat1, int index1,
321 const SoMaterial *mat2, int index2);
322
323 // For each of the 6 sliders (or sets of sliders) sets the ignore flag of
324 // the material node being editted to FALSE if it has been changed.
325 void undoIgnoresIfChanged();
326
327 // copy/paste support
328 static void pasteDone(void *userData, SoPathList *pathList);
329
330 // Callback routines from components
331 static void materialListCB(void *, const SoMaterial *);
332 static void colorEditorCB(void *, const SbColor *);
333 static void ambientSliderCB(void *, float);
334 static void diffuseSliderCB(void *, float);
335 static void specularSliderCB(void *, float);
336 static void emissiveSliderCB(void *, float);
337 static void shininessSliderCB(void *, float);
338 static void transparencySliderCB(void *, float);
339
340 // Callback routines from Xt/Motif
341 static void menuPick(SoWidget, int, XmAnyCallbackStruct *);
342 static void menuDisplay(SoWidget, SoXtMaterialEditor *, XtPointer);
343 static void radioButtonPick(SoWidget, int, XtPointer);
344 static void diamondButtonPick(SoWidget, int, XtPointer);
345 static void acceptButtonCB(SoWidget, SoXtMaterialEditor *, XtPointer);
346
347 // Sensor callbacks
348 static void sensorCB(void *, SoSensor *);
349
350 // Build routines
351 SoWidget buildPulldownMenu(SoWidget parent);
352 SoWidget buildControls(SoWidget parent);
353 SoWidget buildSlidersForm(SoWidget parent);
354
355 static void visibilityChangeCB(void *pt, SbBool visible);
356 void activate(); // connects the sensor
357 void deactivate(); // disconnects the sensor
358
359 // this is called by both constructors
360 void constructorCommon(SbBool buildNow);
361
362};
363
364
365// Inline functions
366void
368 SoXtMaterialEditorCB *f,
369 void *userData)
370{ callbackList->addCallback((SoCallbackListCB *) f, userData); }
371
372void
374 SoXtMaterialEditorCB *f,
375 void *userData)
376{ callbackList->removeCallback((SoCallbackListCB *) f, userData); }
377
378#endif // _SO_XT_MATERIAL_EDITOR_
379
380#endif // _WIN32
381
382
Color vector class.
Definition SbColor.h:82
Class for smart character strings.
Definition SbString.h:202
Node that defines an object's base color.
Definition SoBaseColor.h:91
Base class for all nodes, paths, and engines.
Definition SoBase.h:111
Manages a list of callbacks and associated data.
void addCallback(SoCallbackListCB *f, void *userData=NULL)
Adds a function to the list of callback functions.
void removeCallback(SoCallbackListCB *f, void *userData=NULL)
Removes a function from the list of callback functions.
Node representing a directional light source.
Multiple-value field containing any number of RGB colors stored as three floats.
Definition SoMFColor.h:98
Surface material definition node.
Definition SoMaterial.h:173
Abstract base class for all database nodes.
Definition SoNode.h:145
Sensor class that can be attached to Open Inventor nodes.
Maintains a list of pointers to paths.
Definition SoPathList.h:81
Field containing an RGB color.
Definition SoSFColor.h:82
Manages a list of selected objects.
Abstract base class for Open Inventor sensors.
Definition SoSensor.h:100
Group node that saves and restores traversal state.
Supports copy/paste for Open Inventor using the Xt clipboard.
Component that lets you edit a color interactively.
Abstract base class for all Open Inventor components.
Component which lets you edit a material interactively.
void attach(SoMaterial *material, int index=0)
Attaches the editor to a material node and edits the material of the given index.
virtual void hide()
This hides the component.
~SoXtMaterialEditor()
Destructor.
UpdateFrequency
UpdateFrequency is how often new values should be sent to the node or the callback routine.
@ CONTINUOUS
Send updates with every mouse motion.
@ AFTER_ACCEPT
Only send updates after user hits accept button.
const SoMaterial & getMaterial() const
Gets the current material value.
virtual void show()
This shows the component.
SbBool isAttached()
Returns TRUE if the editor is attached.
void addMaterialChangedCallback(SoXtMaterialEditorCB *f, void *userData=NULL)
Additional way of using the material editor, by registering a callback which will be called whenever ...
SoXtMaterialEditor(SoWidget parent=NULL, const char *name=NULL, SbBool buildInsideParent=TRUE)
Constructor.
void SoXtMaterialEditorCB(void *userData, const SoMaterial *mtl)
void detach()
Detaches the editor from the material node.
SoXtMaterialEditor::UpdateFrequency getUpdateFrequency()
Gets the update frequency.
void removeMaterialChangedCallback(SoXtMaterialEditorCB *f, void *userData=NULL)
Removes the material changed callback.
void setMaterial(const SoMaterial &mtl)
Sets a new material value.
void setUpdateFrequency(SoXtMaterialEditor::UpdateFrequency freq)
Sets the update frequency.
Component which lets you edit a material interactively.
Component for rendering Open Inventor scene graphs.
int SbBool
Boolean type.
Definition SbBase.h:87
void * XtPointer
Definition SoQtDef.h:122