| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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 the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program 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 General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup RNA | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <time.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_windowmanager_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-18 07:58:37 +02:00
										 |  |  | #include "RNA_enum_types.h" /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | #include "rna_internal.h" /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef RNA_RUNTIME
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 16:24:22 +10:00
										 |  |  | #  include "BKE_paint.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 17:19:25 +02:00
										 |  |  | #  include "ED_screen.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 14:36:36 +11:00
										 |  |  | static void rna_WorkSpaceTool_setup(ID *id, | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |                                     bToolRef *tref, | 
					
						
							|  |  |  |                                     bContext *C, | 
					
						
							| 
									
										
										
										
											2019-12-07 03:45:50 +11:00
										 |  |  |                                     const char *idname, | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |                                     /* Args for: 'bToolRef_Runtime'. */ | 
					
						
							| 
									
										
										
										
											2018-05-18 07:58:37 +02:00
										 |  |  |                                     int cursor, | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |                                     const char *keymap, | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |                                     const char *gizmo_group, | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |                                     const char *data_block, | 
					
						
							| 
									
										
										
										
											2019-10-24 18:15:08 +11:00
										 |  |  |                                     const char *op_idname, | 
					
						
							| 
									
										
										
										
											2019-12-07 03:45:50 +11:00
										 |  |  |                                     int index, | 
					
						
							|  |  |  |                                     const char *idname_fallback, | 
					
						
							|  |  |  |                                     const char *keymap_fallback) | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   bToolRef_Runtime tref_rt = {0}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-18 07:58:37 +02:00
										 |  |  |   tref_rt.cursor = cursor; | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   STRNCPY(tref_rt.keymap, keymap); | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |   STRNCPY(tref_rt.gizmo_group, gizmo_group); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   STRNCPY(tref_rt.data_block, data_block); | 
					
						
							| 
									
										
										
										
											2019-10-24 18:15:08 +11:00
										 |  |  |   STRNCPY(tref_rt.op, op_idname); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   tref_rt.index = index; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-03 12:26:36 +11:00
										 |  |  |   /* While it's logical to assign both these values from setup,
 | 
					
						
							|  |  |  |    * it's useful to stored this in DNA for re-use, exceptional case: write to the 'tref'. */ | 
					
						
							|  |  |  |   STRNCPY(tref->idname_fallback, idname_fallback); | 
					
						
							| 
									
										
										
										
											2019-12-12 21:09:22 +11:00
										 |  |  |   STRNCPY(tref_rt.keymap_fallback, keymap_fallback); | 
					
						
							| 
									
										
										
										
											2019-12-07 03:45:50 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |   WM_toolsystem_ref_set_from_runtime(C, (WorkSpace *)id, tref, &tref_rt, idname); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 14:36:36 +11:00
										 |  |  | static void rna_WorkSpaceTool_refresh_from_context(ID *id, bToolRef *tref, Main *bmain) | 
					
						
							| 
									
										
										
										
											2018-08-02 16:24:22 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-07 08:42:15 +11:00
										 |  |  |   WM_toolsystem_ref_sync_from_context(bmain, (WorkSpace *)id, tref); | 
					
						
							| 
									
										
										
										
											2018-08-02 16:24:22 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 14:36:36 +11:00
										 |  |  | static PointerRNA rna_WorkSpaceTool_operator_properties(bToolRef *tref, | 
					
						
							| 
									
										
										
										
											2018-10-02 15:28:14 +10:00
										 |  |  |                                                         ReportList *reports, | 
					
						
							| 
									
										
										
										
											2018-05-22 14:00:44 +02:00
										 |  |  |                                                         const char *idname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   wmOperatorType *ot = WM_operatortype_find(idname, true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 14:00:44 +02:00
										 |  |  |   if (ot != NULL) { | 
					
						
							|  |  |  |     PointerRNA ptr; | 
					
						
							| 
									
										
										
										
											2018-10-02 15:39:20 +10:00
										 |  |  |     WM_toolsystem_ref_properties_ensure_from_operator(tref, ot, &ptr); | 
					
						
							| 
									
										
										
										
											2018-05-22 14:00:44 +02:00
										 |  |  |     return ptr; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-10-02 15:28:14 +10:00
										 |  |  |   else { | 
					
						
							|  |  |  |     BKE_reportf(reports, RPT_ERROR, "Operator '%s' not found!", idname); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-05-22 14:00:44 +02:00
										 |  |  |   return PointerRNA_NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 14:36:36 +11:00
										 |  |  | static PointerRNA rna_WorkSpaceTool_gizmo_group_properties(bToolRef *tref, | 
					
						
							| 
									
										
										
										
											2018-10-02 16:59:54 +10:00
										 |  |  |                                                            ReportList *reports, | 
					
						
							|  |  |  |                                                            const char *idname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); | 
					
						
							|  |  |  |   if (gzgt != NULL) { | 
					
						
							|  |  |  |     PointerRNA ptr; | 
					
						
							|  |  |  |     WM_toolsystem_ref_properties_ensure_from_gizmo_group(tref, gzgt, &ptr); | 
					
						
							|  |  |  |     return ptr; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     BKE_reportf(reports, RPT_ERROR, "Gizmo group '%s' not found!", idname); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return PointerRNA_NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 17:19:25 +02:00
										 |  |  | void RNA_api_workspace(StructRNA *srna) | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-26 17:19:25 +02:00
										 |  |  |   FunctionRNA *func; | 
					
						
							| 
									
										
										
										
											2018-10-30 08:55:36 +11:00
										 |  |  |   PropertyRNA *parm; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-08 14:21:41 +11:00
										 |  |  |   func = RNA_def_function(srna, "status_text_set_internal", "ED_workspace_status_text"); | 
					
						
							| 
									
										
										
										
											2018-06-26 17:19:25 +02:00
										 |  |  |   RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT); | 
					
						
							| 
									
										
										
										
											2018-06-28 12:06:00 +02:00
										 |  |  |   RNA_def_function_ui_description( | 
					
						
							|  |  |  |       func, "Set the status bar text, typically key shortcuts for modal operators"); | 
					
						
							| 
									
										
										
										
											2018-10-30 16:16:41 +11:00
										 |  |  |   parm = RNA_def_string( | 
					
						
							|  |  |  |       func, "text", NULL, 0, "Text", "New string for the status bar, None clears the text"); | 
					
						
							| 
									
										
										
										
											2018-10-30 08:55:36 +11:00
										 |  |  |   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | 
					
						
							| 
									
										
										
										
											2018-10-30 16:16:41 +11:00
										 |  |  |   RNA_def_property_clear_flag(parm, PROP_NEVER_NULL); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RNA_api_workspace_tool(StructRNA *srna) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PropertyRNA *parm; | 
					
						
							|  |  |  |   FunctionRNA *func; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 14:36:36 +11:00
										 |  |  |   func = RNA_def_function(srna, "setup", "rna_WorkSpaceTool_setup"); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_CONTEXT); | 
					
						
							|  |  |  |   RNA_def_function_ui_description(func, "Set the tool settings"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 12:45:41 +11:00
										 |  |  |   parm = RNA_def_string(func, "idname", NULL, MAX_NAME, "Identifier", ""); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   /* 'bToolRef_Runtime' */ | 
					
						
							| 
									
										
										
										
											2018-05-18 07:58:37 +02:00
										 |  |  |   parm = RNA_def_property(func, "cursor", PROP_ENUM, PROP_NONE); | 
					
						
							|  |  |  |   RNA_def_property_enum_items(parm, rna_enum_window_cursor_items); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   RNA_def_string(func, "keymap", NULL, KMAP_MAX_NAME, "Key Map", ""); | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |   RNA_def_string(func, "gizmo_group", NULL, MAX_NAME, "Gizmo Group", ""); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   RNA_def_string(func, "data_block", NULL, MAX_NAME, "Data Block", ""); | 
					
						
							| 
									
										
										
										
											2018-07-03 18:33:52 +02:00
										 |  |  |   RNA_def_string(func, "operator", NULL, MAX_NAME, "Operator", ""); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  |   RNA_def_int(func, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-07 03:45:50 +11:00
										 |  |  |   RNA_def_string(func, "idname_fallback", NULL, MAX_NAME, "Fallback Identifier", ""); | 
					
						
							|  |  |  |   RNA_def_string(func, "keymap_fallback", NULL, KMAP_MAX_NAME, "Fallback Key Map", ""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 14:00:44 +02:00
										 |  |  |   /* Access tool operator options (optionally create). */ | 
					
						
							| 
									
										
										
										
											2019-03-14 14:36:36 +11:00
										 |  |  |   func = RNA_def_function(srna, "operator_properties", "rna_WorkSpaceTool_operator_properties"); | 
					
						
							| 
									
										
										
										
											2018-10-02 15:28:14 +10:00
										 |  |  |   RNA_def_function_flag(func, FUNC_USE_REPORTS); | 
					
						
							| 
									
										
										
										
											2018-05-22 14:00:44 +02:00
										 |  |  |   parm = RNA_def_string(func, "operator", NULL, 0, "", ""); | 
					
						
							|  |  |  |   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | 
					
						
							|  |  |  |   /* return */ | 
					
						
							|  |  |  |   parm = RNA_def_pointer(func, "result", "OperatorProperties", "", ""); | 
					
						
							|  |  |  |   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR); | 
					
						
							|  |  |  |   RNA_def_function_return(func, parm); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 16:59:54 +10:00
										 |  |  |   /* Access gizmo-group options (optionally create). */ | 
					
						
							| 
									
										
										
										
											2019-03-14 14:36:36 +11:00
										 |  |  |   func = RNA_def_function( | 
					
						
							|  |  |  |       srna, "gizmo_group_properties", "rna_WorkSpaceTool_gizmo_group_properties"); | 
					
						
							| 
									
										
										
										
											2018-10-02 16:59:54 +10:00
										 |  |  |   RNA_def_function_flag(func, FUNC_USE_REPORTS); | 
					
						
							|  |  |  |   parm = RNA_def_string(func, "group", NULL, 0, "", ""); | 
					
						
							|  |  |  |   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | 
					
						
							|  |  |  |   /* return */ | 
					
						
							|  |  |  |   parm = RNA_def_pointer(func, "result", "GizmoGroupProperties", "", ""); | 
					
						
							|  |  |  |   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR); | 
					
						
							|  |  |  |   RNA_def_function_return(func, parm); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 14:36:36 +11:00
										 |  |  |   func = RNA_def_function(srna, "refresh_from_context", "rna_WorkSpaceTool_refresh_from_context"); | 
					
						
							| 
									
										
										
										
											2018-08-02 16:24:22 +10:00
										 |  |  |   RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN); | 
					
						
							| 
									
										
										
										
											2018-05-16 18:41:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |